Skip to content

Commit f3ee72b

Browse files
committed
Correct regex to only match type(...) comparisons
1 parent 861c9a4 commit f3ee72b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pycodestyle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
144144
r'\s*(?(1)|(None|False|True))\b')
145145
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?<!is\s)(not)\s+[^][)(}{ ]+\s+'
146146
r'(in|is)\s')
147-
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s+type(?:s.\w+Type'
148-
r'|\s*\(\s*([^)]*[^ )])\s*\))')
147+
COMPARE_TYPE_REGEX = re.compile(
148+
r'(?:[=!]=|is(?:\s+not)?)\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))' +
149+
r'|type(?:\s*\(\s*([^)]*[^ )])\s*\))\s+(?:[=!]=|is(?:\s+not)?)'
150+
)
149151
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
150152
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)')
151153
LAMBDA_REGEX = re.compile(r'\blambda\b')

0 commit comments

Comments
 (0)