diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py index 259ddc84aaf1..1fa465c1a278 100644 --- a/Lib/lib2to3/fixes/fix_import.py +++ b/Lib/lib2to3/fixes/fix_import.py @@ -45,7 +45,7 @@ def transform(self, node, results): node.changed() else: new = FromImport('.', getattr(imp, 'content', None) or [imp]) - new.prefix = node.get_prefix() + new.set_prefix(node.get_prefix()) node = new return node diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py index eccbfc0f20e1..f5aaa8d4d1ec 100755 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -3319,6 +3319,17 @@ def test_dotted_import_as(self): a = "from . import foo.bar as bang" self.check_both(b, a) + def test_prefix(self): + b = """ + # prefix + import foo.bar + """ + a = """ + # prefix + from . import foo.bar + """ + self.check_both(b, a) + if __name__ == "__main__": import __main__