From 69a3a3da9ed280831787bcecd6ee47caa2969571 Mon Sep 17 00:00:00 2001 From: Qiangning Hong Date: Fri, 8 Aug 2014 11:15:24 +0800 Subject: allow use # noqa to disable E721 warning Sometimes `isinstance()` is not suitable for comparing types. For example, someone may want to make sure an object is exact instance of a type, not instance of its subclasses. --- docs/intro.rst | 2 +- pep8.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/intro.rst b/docs/intro.rst index 5e3af1f..806bbba 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -323,7 +323,7 @@ This is the current list of error and warning codes: +----------+----------------------------------------------------------------------+ | E714 | test for object identity should be 'is not' | +----------+----------------------------------------------------------------------+ -| E721 | do not compare types, use 'isinstance()' | +| E721 (^) | do not compare types, use 'isinstance()' | +----------+----------------------------------------------------------------------+ | E731 | do not assign a lambda expression, use a def | +----------+----------------------------------------------------------------------+ diff --git a/pep8.py b/pep8.py index b31a978..8a83e3e 100755 --- a/pep8.py +++ b/pep8.py @@ -974,7 +974,7 @@ def comparison_negative(logical_line): yield pos, "E714 test for object identity should be 'is not'" -def comparison_type(logical_line): +def comparison_type(logical_line, noqa): r"""Object type comparisons should always use isinstance(). Do not compare types directly. @@ -990,7 +990,7 @@ def comparison_type(logical_line): Okay: if type(a1) is type(b1): """ match = COMPARE_TYPE_REGEX.search(logical_line) - if match: + if match and not noqa: inst = match.group(1) if inst and isidentifier(inst) and inst not in SINGLETONS: return # Allow comparison for types which are not obvious -- cgit v1.2.1