Back to index

python3.2  3.2.2
Classes | Functions
lib2to3.fixes.fix_import Namespace Reference

Classes

class  FixImport

Functions

def traverse_imports

Detailed Description

Fixer for import statements.
If spam is being imported from the local directory, this import:
    from spam import eggs
Becomes:
    from .spam import eggs

And this import:
    import spam
Becomes:
    from . import spam

Function Documentation

Walks over all the names imported in a dotted_as_names node.

Definition at line 19 of file fix_import.py.

00019 
00020 def traverse_imports(names):
00021     """
00022     Walks over all the names imported in a dotted_as_names node.
00023     """
00024     pending = [names]
00025     while pending:
00026         node = pending.pop()
00027         if node.type == token.NAME:
00028             yield node.value
00029         elif node.type == syms.dotted_name:
00030             yield "".join([ch.value for ch in node.children])
00031         elif node.type == syms.dotted_as_name:
00032             pending.append(node.children[0])
00033         elif node.type == syms.dotted_as_names:
00034             pending.extend(node.children[::-2])
00035         else:
00036             raise AssertionError("unkown node type")
00037 

Here is the caller graph for this function: