Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E714: fix chained is not #931

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)')
COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)'
r'\s*(?(1)|(None|False|True))\b')
COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s')
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.\w+Type'
r'|\s*\(\s*([^)]*[^ )])\s*\))')
KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
Expand Down
9 changes: 9 additions & 0 deletions testsuite/E71.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
#: E714
if not X.B is Y:
pass
#: E714
if not X is Y is not Z:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit silly but does this still trigger E714 (I think it should, even though it's absurd)?

if not X is not Y:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've adjusted the regex and added it as a test case.

So it will now catch the pattern not X is/in like before except when it's preceded by the keyword is.

pass
#: E714
if not X is not Y:
pass

#
#: Okay
Expand All @@ -79,6 +85,9 @@
if x is not y:
pass

if X is not Y is not Z:
pass

if TrueElement.get_element(True) == TrueElement.get_element(False):
pass

Expand Down