_importclns module

exception pyflyby._importclns.ConflictingImportsError
class pyflyby._importclns.ImportMap

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 ImportMap is an immutable data structure.

_EMPTY = ImportMap({})
classmethod _from_map(arg)
classmethod _merge(maps)
items()
iteritems()
iterkeys()
keys()
values()
without_imports(removals)

Return a copy of self without the given imports. Matches both keys and values.

class pyflyby._importclns.ImportSet

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 ImportSet is an immutable data structure.

_EMPTY = ImportSet(''' ''')
_by_module_name

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

classmethod _from_args(args, ignore_nonimports=False, ignore_shadowed=False)
Parameters
  • ignore_nonimports – If False, complain about non-imports. If True, ignore non-imports.

  • ignore_shadowed – See ImportSet.__new__.

Return type

ImportSet

classmethod _from_imports(imports, ignore_shadowed=False)
Parameters

ignore_shadowed – See ImportSet.__new__.

Return type

ImportSet

by_import_as

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

conflicting_imports

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

flags

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

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 of ImportStatement s

imports

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

member_names

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

pretty_print(params=None, allow_conflicts=False)

Pretty-print a block of import statements into a single string.

Return type

str

statements

Computes attribute value and caches it in instance.

Example:

class MyClass(object):
    @cached_attribute
    def myMethod(self):
        # ...

Use “del inst.myMethod” to clear cache.

with_imports(other)

Return a new ImportSet that is the union of self and new_imports.

>>> impset = ImportSet('from m import t1, t2, t3')
>>> impset.with_imports('import m.t2a as t2b')
ImportSet('''
  from m import t1, t2, t2a as t2b, t3
''')
Return type

ImportSet

without_imports(removals)

Return a copy of self without the given imports.

>>> imports = ImportSet('from m import t1, t2, t3, t4')
>>> imports.without_imports(['from m import t3'])
ImportSet('''
  from m import t1, t2, t4
''')
Return type

ImportSet

exception pyflyby._importclns.NoSuchImportError