Skip to content

Commit b7bf8c8

Browse files
committed
complain about missing space before opening parentheses of import statement
Solves issue PyCQA#489
1 parent 2e151c5 commit b7bf8c8

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docs/intro.rst

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ This is the current list of error and warning codes:
313313
+------------+----------------------------------------------------------------------+
314314
| E274 | tab before keyword |
315315
+------------+----------------------------------------------------------------------+
316+
| E275 | missing whitespace after keyword |
317+
+------------+----------------------------------------------------------------------+
316318
+------------+----------------------------------------------------------------------+
317319
| **E3** | *Blank line* |
318320
+------------+----------------------------------------------------------------------+

pep8.py

+17
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,23 @@ def whitespace_around_keywords(logical_line):
325325
yield match.start(2), "E271 multiple spaces after keyword"
326326

327327

328+
def missing_whitespace_after_import_keyword(logical_line):
329+
r"""Multiple imports in form from x import (a, b, c) should have space
330+
between import statement and parenthesised name list.
331+
332+
Okay: from foo import (bar, baz)
333+
E275: from foo import(bar, baz)
334+
E275: from importable.module import(bar, baz)
335+
"""
336+
line = logical_line
337+
indicator = ' import('
338+
if line.startswith('from '):
339+
found = line.find(indicator)
340+
if -1 < found:
341+
pos = found + len(indicator) - 1
342+
yield pos, "E275 missing whitespace after keyword"
343+
344+
328345
def missing_whitespace(logical_line):
329346
r"""Each comma, semicolon or colon should be followed by whitespace.
330347

testsuite/E27.py

+14
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@
2828
a and b
2929
#: E273 E274
3030
this and False
31+
#: Okay
32+
from u import (a, b)
33+
from v import c, d
34+
#: E271
35+
from w import (e, f)
36+
#: E275
37+
from w import(e, f)
38+
#: E275
39+
from importable.module import(e, f)
40+
#: E275
41+
try:
42+
from importable.module import(e, f)
43+
except ImportError:
44+
pass

0 commit comments

Comments
 (0)