Skip to content

Commit

Permalink
Optimize sqlparse.utils.imt().
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Mar 9, 2024
1 parent 60486b9 commit e7eab4c
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

Check warning on line 102 in sqlparse/utils.py

View check run for this annotation

Codecov / codecov/patch

sqlparse/utils.py#L101-L102

Added lines #L101 - L102 were not covered by tests
elif token.ttype in t:
return True
return False


def consume(iterator, n):
Expand Down

0 comments on commit e7eab4c

Please sign in to comment.