Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize sqlparse.utils.imt(). #766

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
: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
andialbrecht marked this conversation as resolved.
Show resolved Hide resolved
elif token.ttype in t:
return True
return False


def consume(iterator, n):
Expand Down
Loading