diff --git a/pycodestyle.py b/pycodestyle.py index f9c236a1..876fc0db 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -128,8 +128,10 @@ r'\s*(?(1)|(None|False|True))\b') COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?%&^]+|:=)(\s*)') LAMBDA_REGEX = re.compile(r'\blambda\b') @@ -1457,14 +1459,7 @@ def comparison_type(logical_line, noqa): Do not compare types directly. 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): + E721: if type(obj) == type(1): """ match = COMPARE_TYPE_REGEX.search(logical_line) if match and not noqa: diff --git a/testsuite/E72.py b/testsuite/E72.py index d127ff77..ac55a958 100644 --- a/testsuite/E72.py +++ b/testsuite/E72.py @@ -4,12 +4,12 @@ #: E721 if type(res) != type(""): pass -#: E721 +#: Okay import types if res == types.IntType: pass -#: E721 +#: Okay import types if type(res) is not types.ListType: @@ -26,9 +26,9 @@ assert type(res) == type((0)) #: E721 assert type(res) != type((1, )) -#: E721 +#: Okay assert type(res) is type((1, )) -#: E721 +#: Okay assert type(res) is not type((1, )) #: E211 E721 assert type(res) == type ([2, ]) @@ -47,8 +47,6 @@ 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 @@ -81,6 +79,11 @@ 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: