Skip to content

Commit

Permalink
Merge pull request #1085 from PyCQA/revert-1041
Browse files Browse the repository at this point in the history
Revert "Merge pull request #1041 from asfaltboy/issue-830-e721-types-regex-incorrect"
  • Loading branch information
asottile committed Jul 30, 2022
2 parents d356662 + c14bd2a commit ab806f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 9 additions & 4 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,8 @@
r'\s*(?(1)|(None|False|True))\b')
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?<!is\s)(not)\s+[^][)(}{ ]+\s+'
r'(in|is)\s')
COMPARE_TYPE_REGEX = re.compile(
r'(?:[=!]=|is(?:\s+not)?)\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))' +
r'|\btype(?:\s*\(\s*([^)]*[^ )])\s*\))\s+(?:[=!]=|is(?:\s+not)?)'
)
COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s+type(?:s.\w+Type'
r'|\s*\(\s*([^)]*[^ )])\s*\))')
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)')
LAMBDA_REGEX = re.compile(r'\blambda\b')
Expand Down Expand Up @@ -1446,6 +1444,13 @@ def comparison_type(logical_line, noqa):
Okay: if isinstance(obj, int):
E721: if type(obj) is type(1):
When checking if an object is a string, keep in mind that it might
be a unicode string too! In Python 2.3, str and unicode have a
common base class, basestring, so you can do:
Okay: if isinstance(obj, basestring):
Okay: if type(a1) is type(b1):
"""
match = COMPARE_TYPE_REGEX.search(logical_line)
if match and not noqa:
Expand Down
9 changes: 3 additions & 6 deletions testsuite/E72.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#: E721
if type(res) != type(""):
pass
#: Okay
#: E721
import types

if res == types.IntType:
Expand Down Expand Up @@ -47,6 +47,8 @@
pass
if isinstance(res, types.MethodType):
pass
if type(a) != type(b) or type(a) == type(ccc):
pass
#: Okay
def func_histype(a, b, c):
pass
Expand Down Expand Up @@ -79,11 +81,6 @@ def func_histype(a, b, c):
except Exception:
pass
#: Okay
from . import custom_types as types

red = types.ColorTypeRED
red is types.ColorType.RED
#: Okay
from . import compute_type

if compute_type(foo) == 5:
Expand Down

0 comments on commit ab806f3

Please sign in to comment.