Skip to content

Commit

Permalink
Optimize sqlparse.utils.imt().
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored and andialbrecht committed Mar 17, 2024
1 parent 46971e5 commit 012c9f1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sqlparse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,23 @@ def imt(token, i=None, m=None, t=None):
:param t: TokenType or Tuple/List of TokenTypes
:return: bool
"""
clss = i
types = [t, ] if t and not isinstance(t, list) else t
mpatterns = [m, ] if m and not isinstance(m, list) else m

if token is None:
return False
elif clss and isinstance(token, clss):
return True
elif mpatterns and any(token.match(*pattern) for pattern in mpatterns):
if i and isinstance(token, i):
return True
elif types and any(token.ttype in ttype for ttype in types):
return True
else:
return False
if m:
if isinstance(m, list):
if any(token.match(*pattern) for pattern in m):
return True
elif token.match(*m):
return True
if t:
if isinstance(t, list):
if any(token.ttype in ttype for ttype in t):
return True
elif token.ttype in t:
return True
return False


def consume(iterator, n):
Expand Down

0 comments on commit 012c9f1

Please sign in to comment.