mirror of
https://github.com/python/cpython.git
synced 2024-11-24 00:38:00 +01:00
gh-92986: Fix ast.unparse when ImportFrom.level is None (#92992)
This doesn't happen naturally, but is allowed by the ASDL and compiler. We don't want to change ASDL for backward compatibility reasons (#57645, #92987)
This commit is contained in:
parent
2c7d2e8d46
commit
200c9a8da0
@ -853,7 +853,7 @@ class _Unparser(NodeVisitor):
|
||||
|
||||
def visit_ImportFrom(self, node):
|
||||
self.fill("from ")
|
||||
self.write("." * node.level)
|
||||
self.write("." * (node.level or 0))
|
||||
if node.module:
|
||||
self.write(node.module)
|
||||
self.write(" import ")
|
||||
|
@ -422,6 +422,12 @@ class UnparseTestCase(ASTTestCase):
|
||||
def test_invalid_yield_from(self):
|
||||
self.check_invalid(ast.YieldFrom(value=None))
|
||||
|
||||
def test_import_from_level_none(self):
|
||||
tree = ast.ImportFrom(module='mod', names=[ast.alias(name='x')])
|
||||
self.assertEqual(ast.unparse(tree), "from mod import x")
|
||||
tree = ast.ImportFrom(module='mod', names=[ast.alias(name='x')], level=None)
|
||||
self.assertEqual(ast.unparse(tree), "from mod import x")
|
||||
|
||||
def test_docstrings(self):
|
||||
docstrings = (
|
||||
'this ends with double quote"',
|
||||
|
@ -0,0 +1 @@
|
||||
Fix :func:`ast.unparse` when ``ImportFrom.level`` is None
|
Loading…
Reference in New Issue
Block a user