From 1088b0f6d35229d2e0a06055abae9b4beb1df66d Mon Sep 17 00:00:00 2001 From: isidentical Date: Fri, 10 Jan 2020 20:23:51 +0300 Subject: [PATCH] bpo-39290: Add support for import_as_names for traverse_imports --- Lib/lib2to3/fixes/fix_import.py | 4 ++-- .../next/Library/2020-01-10-20-22-04.bpo-39290.RsTxpx.rst | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-01-10-20-22-04.bpo-39290.RsTxpx.rst diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py index 734ca294699c36..8043dfcfc71956 100644 --- a/Lib/lib2to3/fixes/fix_import.py +++ b/Lib/lib2to3/fixes/fix_import.py @@ -27,9 +27,9 @@ def traverse_imports(names): yield node.value elif node.type == syms.dotted_name: yield "".join([ch.value for ch in node.children]) - elif node.type == syms.dotted_as_name: + elif node.type in {syms.dotted_as_name, syms.import_as_name}: pending.append(node.children[0]) - elif node.type == syms.dotted_as_names: + elif node.type in {syms.dotted_as_names, syms.import_as_names}: pending.extend(node.children[::-2]) else: raise AssertionError("unknown node type") diff --git a/Misc/NEWS.d/next/Library/2020-01-10-20-22-04.bpo-39290.RsTxpx.rst b/Misc/NEWS.d/next/Library/2020-01-10-20-22-04.bpo-39290.RsTxpx.rst new file mode 100644 index 00000000000000..2129613ddc72d4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-10-20-22-04.bpo-39290.RsTxpx.rst @@ -0,0 +1,2 @@ +Add imports_as_name support to ``traverse_imports`` in +``lib2to3.fixes.fix_import``.