Skip to content

Commit 012c9f1

Browse files
adamchainzandialbrecht
authored andcommitted
Optimize sqlparse.utils.imt().
1 parent 46971e5 commit 012c9f1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

sqlparse/utils.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,23 @@ def imt(token, i=None, m=None, t=None):
8686
:param t: TokenType or Tuple/List of TokenTypes
8787
:return: bool
8888
"""
89-
clss = i
90-
types = [t, ] if t and not isinstance(t, list) else t
91-
mpatterns = [m, ] if m and not isinstance(m, list) else m
92-
9389
if token is None:
9490
return False
95-
elif clss and isinstance(token, clss):
96-
return True
97-
elif mpatterns and any(token.match(*pattern) for pattern in mpatterns):
91+
if i and isinstance(token, i):
9892
return True
99-
elif types and any(token.ttype in ttype for ttype in types):
100-
return True
101-
else:
102-
return False
93+
if m:
94+
if isinstance(m, list):
95+
if any(token.match(*pattern) for pattern in m):
96+
return True
97+
elif token.match(*m):
98+
return True
99+
if t:
100+
if isinstance(t, list):
101+
if any(token.ttype in ttype for ttype in t):
102+
return True
103+
elif token.ttype in t:
104+
return True
105+
return False
103106

104107

105108
def consume(iterator, n):

0 commit comments

Comments
 (0)