Skip to content

Commit 5307647

Browse files
authored
Make TYPE_CHECKING less fragile with whitespace (#215)
Closes #214
1 parent de264ac commit 5307647

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

flake8_import_order/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"modules",
3939
"names",
4040
"lineno",
41+
"end_lineno",
4142
"level",
4243
"package",
4344
"type_checking",
@@ -113,6 +114,7 @@ def visit_Import(self, node): # noqa: N802
113114
modules,
114115
[],
115116
node.lineno,
117+
node.end_lineno,
116118
0,
117119
root_package_name(modules[0]),
118120
self._type_checking_import(node),
@@ -133,6 +135,7 @@ def visit_ImportFrom(self, node): # noqa: N802
133135
[module],
134136
names,
135137
node.lineno,
138+
node.end_lineno,
136139
node.level,
137140
root_package_name(module),
138141
self._type_checking_import(node),

flake8_import_order/styles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _check_I101(self, current_import): # noqa: N802
7878
)
7979

8080
def _check_I300(self, previous_import, current_import): # noqa: N802
81-
if current_import.lineno - previous_import.lineno != 3:
81+
if current_import.lineno - previous_import.end_lineno != 3:
8282
yield Error(
8383
current_import.lineno,
8484
"I300",

tests/test_cases/additional_newline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
from . import A
2323

2424
from . import B # I202
25+
from .Z import (
26+
A,
27+
B,
28+
C,
29+
D,
30+
E,
31+
F,
32+
G,
33+
)
2534

2635
if TYPE_CHECKING:
2736
import ast

tests/test_cases/complete_google.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
from .. import B
3232
from ..A import A
3333
from ..B import B
34+
from ..Z import (
35+
A,
36+
B,
37+
C,
38+
D,
39+
E,
40+
F,
41+
G,
42+
H,
43+
)
3444

3545
if TYPE_CHECKING:
3646
import ast

tests/test_style_cases.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ def _checker(filename, tree, style_entry_point):
6767
)
6868
def test_styles(filename, tree, style, expected_codes):
6969
checker = _checker(filename, tree, style)
70-
codes = [error.code for error in checker.check_order()]
71-
assert codes == expected_codes
70+
codes = [
71+
(filename, error.lineno, error.code)
72+
for error in checker.check_order()
73+
]
74+
assert [i[2] for i in codes] == expected_codes, codes
7275

7376

7477
def test_unknown_style():

0 commit comments

Comments
 (0)