Skip to content

Commit 1d19c8d

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

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/intro.rst

+2
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ This is the current list of error and warning codes:
331331
+------------+----------------------------------------------------------------------+
332332
| E402 | module level import not at top of file |
333333
+------------+----------------------------------------------------------------------+
334+
| E403 | missing whitespace after import statement |
335+
+------------+----------------------------------------------------------------------+
334336
+------------+----------------------------------------------------------------------+
335337
| **E5** | *Line length* |
336338
+------------+----------------------------------------------------------------------+

pep8.py

+15
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,21 @@ def imports_on_separate_lines(logical_line):
855855
yield found, "E401 multiple imports on one line"
856856

857857

858+
def missing_whitespace_after_import_statement(logical_line):
859+
r"""Multiple imports in form from x import (a, b, c) should have space
860+
between import statement and parenthesised name list.
861+
862+
Okay: from foo import (bar, baz)
863+
E403: from foo import(bar, baz)
864+
E403: from fake.importable.module import(bar, baz)
865+
"""
866+
line = logical_line
867+
if line.startswith('from '):
868+
found = line.find(' import')
869+
if -1 < found and line[found + len(" import")] == "(":
870+
yield found, "E403 missing whitespace after import statement"
871+
872+
858873
def module_imports_on_top_of_file(
859874
logical_line, indent_level, checker_state, noqa):
860875
r"""Imports are always put at the top of the file, just after any module

testsuite/E40.py

+12
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@
3636
a = 1
3737

3838
import bar
39+
#: Okay
40+
from u import (a, b)
41+
from v import c, d
42+
#: E403
43+
from w import(e, f)
44+
#: E403
45+
from fake.importable.module import(e, f)
46+
#: E403
47+
try:
48+
from fake.importable.module import(e, f)
49+
except ImportError:
50+
pass

0 commit comments

Comments
 (0)