summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 2cbc2cd..e2e4b96 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -480,20 +480,24 @@ def whitespace_around_keywords(logical_line):
@register_check
-def missing_whitespace_after_import_keyword(logical_line):
- r"""Multiple imports in form from x import (a, b, c) should have
- space between import statement and parenthesised name list.
+def missing_whitespace_after_keyword(logical_line, tokens):
+ r"""Keywords should be followed by whitespace.
Okay: from foo import (bar, baz)
E275: from foo import(bar, baz)
E275: from importable.module import(bar, baz)
+ E275: if(foo): bar
"""
- line = logical_line
- indicator = ' import('
- if line.startswith('from '):
- found = line.find(indicator)
- if -1 < found:
- pos = found + len(indicator) - 1
+ for tok0, tok1 in zip(tokens, tokens[1:]):
+ # This must exclude the True/False/None singletons, which can
+ # appear e.g. as "if x is None:", and async/await, which were
+ # valid identifier names in old Python versions.
+ if (tok0.end == tok1.start and
+ keyword.iskeyword(tok0.string) and
+ tok0.string not in SINGLETONS and
+ tok0.string not in ('async', 'await') and
+ tok1.string not in ':\n'):
+ line, pos = tok0.end
yield pos, "E275 missing whitespace after keyword"