_importclns module
- exception pyflyby._importclns.ConflictingImportsError
- class pyflyby._importclns.ImportMap(arg: Any)
A map from import fullname identifier to fullname identifier.
>>> ImportMap({'a.b': 'aa.bb', 'a.b.c': 'aa.bb.cc'}) ImportMap({'a.b': 'aa.bb', 'a.b.c': 'aa.bb.cc'})
An
ImportMapis an immutable data structure.- _data: Dict
- items()
- Return type:
Any
- iteritems()
- Return type:
Any
- iterkeys()
- Return type:
Iterator[str]
- keys()
- Return type:
Any
- values()
- Return type:
Any
- class pyflyby._importclns.ImportSet(arg: Any, ignore_nonimports: bool = False, ignore_shadowed: bool = False)
Representation of a set of imports organized into import statements.
>>> ImportSet(''' ... from m1 import f1 ... from m2 import f1 ... from m1 import f2 ... import m3.m4 as m34 ... ''') ImportSet(''' from m1 import f1, f2 from m2 import f1 from m3 import m4 as m34 ''')
An
ImportSetis an immutable data structure.- property _by_module_name: Tuple[Dict[str, FrozenSet[Import]], ...]
return: (mapping from name to __future__ imports, mapping from name to non-‘from’ imports, mapping from name to ‘from’ imports)
- classmethod _from_args(args, ignore_nonimports=False, ignore_shadowed=False)
- Parameters:
ignore_nonimports (
bool) – IfFalse, complain about non-imports. IfTrue, ignore non-imports.ignore_shadowed (
bool) – See ImportSet.__new__.
- Return type:
SelfImportSet
- classmethod _from_imports(imports, ignore_shadowed=False)
- Parameters:
ignore_shadowed (
bool) – See ImportSet.__new__.- Return type:
SelfImportSet
- _importset: FrozenSet[Import]
- property by_import_as: Dict[str, Tuple[Import, ...]]
Map from
import_asto Import.>>> ImportSet('from aa.bb import cc as dd').by_import_as {'dd': (Import('from aa.bb import cc as dd'),)}
- Return type:
dictmapping fromstrto tuple of Import s
- property conflicting_imports: Tuple[str, ...]
Returns imports that conflict with each other.
>>> ImportSet('import b\nfrom f import a as b\n').conflicting_imports ('b',)
>>> ImportSet('import b\nfrom f import a\n').conflicting_imports ()
- Return type:
bool
- property flags: CompilerFlags
If this contains __future__ imports, then the bitwise-ORed of the compiler_flag values associated with the features. Otherwise, 0.
- get_statements(separate_from_imports=True)
Canonicalized ImportStatement s. These have been merged by module and sorted.
>>> importset = ImportSet(''' ... import a, b as B, c, d.dd as DD ... from __future__ import division ... from _hello import there ... from _hello import * ... from _hello import world ... ''')
>>> for s in importset.get_statements(): print(s) from __future__ import division import a import b as B import c from _hello import * from _hello import there, world from d import dd as DD
- Return type:
Tuple[ImportStatement,...]tupleof ImportStatement s
- property imports: Tuple[Import, ...]
Canonicalized imports, in the same order as
self.statements.- Return type:
tupleof Import s
- property member_names: Dict[str, Tuple[str, ...]]
Map from parent module/package
fullnameto known member names.>>> impset = ImportSet("import numpy.linalg.info\nfrom sys import exit as EXIT") >>> import pprint >>> pprint.pprint(impset.member_names) {'': ('EXIT', 'numpy', 'sys'), 'numpy': ('linalg',), 'numpy.linalg': ('info',), 'sys': ('exit',)}
This is used by the autoimporter module for implementing tab completion.
- Return type:
dictmapping fromstrto tuple ofstr
- pretty_print(params=None, allow_conflicts=False)
Pretty-print a block of import statements into a single string.
- Return type:
strstr
- property statements: Tuple[ImportStatement, ...]
Canonicalized ImportStatement s. These have been merged by module and sorted.
- Return type:
tupleof ImportStatement s
- exception pyflyby._importclns.NoSuchImportError