Skip to content

Commit f6c45af

Browse files
committed
Add skip to fix unnoticed bug with good imports
Fixes logic so that imports that should not be changed are skipped, which was not happening correctly before.
1 parent 818c42c commit f6c45af

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

scripts/flaskext_migrate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def fix_from_imports(red):
4040
from_imports = red.find_all("FromImport")
4141
for x, node in enumerate(from_imports):
4242
values = node.value
43+
if len(values) < 2:
44+
continue
4345
if (values[0].value == 'flask') and (values[1].value == 'ext'):
4446
# Case 1
4547
if len(node.value) == 3:

scripts/test_import_migration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_named_module_import():
4545
assert output == "import flask_foo as foobar"
4646

4747

48-
def test__named_from_import():
48+
def test_named_from_import():
4949
red = RedBaron("from flask.ext.foo import bar as baz")
5050
output = migrate.fix_tester(red)
5151
assert output == "from flask_foo import bar as baz"
@@ -69,3 +69,9 @@ def test_nested_function_call_migration():
6969
output = migrate.fix_tester(red)
7070
assert output == ("import flask_foo\n\n"
7171
"flask_foo.bar(var)")
72+
73+
74+
def test_no_change_to_import():
75+
red = RedBaron("from flask import Flask")
76+
output = migrate.fix_tester(red)
77+
assert output == "from flask import Flask"

0 commit comments

Comments
 (0)