potc.fixture.imports¶
try_import_info¶
-
potc.fixture.imports.
try_import_info
(obj, alias: Optional[str] = None) → Tuple[str, …][source]¶ - Overview:
Try to get an import statement from given object.
- Arguments:
obj (
object
): Given object.alias (
Optional[str]
): Alias name for import statement, default isNone
which means do not alias.
- Returns:
import (
Tuple[str, ...]
): Import statement tuple.
- Example:
>>> import dill >>> try_import_info(dill) # ('import', 'dill') >>> >>> from potc import transvars >>> try_import_info(transvars) # ('from', 'potc', 'import', 'transvars')
ImportStatement¶
-
class
potc.fixture.imports.
ImportStatement
[source]¶ -
abstract
__getstate__
()[source]¶ - Overview:
Get value state of statement.
- Returns:
state: Value state.
-
__repr__
() → str[source]¶ - Overview:
Get representation format.
- Returns:
repr (
str
): Representation format.
-
__str__
() → str[source]¶ - Overview:
Get string format, will check its validity before return.
- Returns:
str (
str
): String format.
-
abstract
_is_valid
() → bool[source]¶ - Overview:
Whether this import statement is valid.
- Return:
valid (
bool
): Is valid or not.
-
abstract
_str
() → str[source]¶ - Overview:
String format of this import statement.
- Returns:
str (
str
): String format.
-
_with_check
()[source]¶ - Overview:
Open a context, do some update and make sure the final statement is valid. If not, this statement will be rolled back, and all the updates will be ignored.
-
abstract property
key
¶ - Overview:
Key value of the import statement. Used for sorting.
-
abstract property
target
¶ - Overview:
Import target.
from aa import bb
–> bb.from aa import bb as cc
–> cc.import aa
–> aa.import aa.bb
–> bb.
Just seen target as the actual sign name of the imported object.
-
abstract
FromImport¶
-
class
potc.fixture.imports.
FromImport
(_from: str, _import: Optional[str] = None, _as: Optional[str] = None)[source]¶ - Overview:
from xxx import yyy as zzz
formatted import statement.
-
__init__
(_from: str, _import: Optional[str] = None, _as: Optional[str] = None)[source]¶ - Overview:
Constructor of
FromImport
.- Arguments:
_from (
str
): From source._import (
Optional[str]
): Import item, default isNone
._as (
Optional[str]
): Alias name, default isNone
which means no alias.
-
__repr__
() → str¶ - Overview:
Get representation format.
- Returns:
repr (
str
): Representation format.
-
__str__
() → str¶ - Overview:
Get string format, will check its validity before return.
- Returns:
str (
str
): String format.
-
_check_valid
()¶ - Overview:
Check if this statement is valid. if not valid, raise
ValueError
.
-
_is_valid
()[source]¶ - Overview:
Whether this import statement is valid.
- Return:
valid (
bool
): Is valid or not.
-
_with_check
()¶ - Overview:
Open a context, do some update and make sure the final statement is valid. If not, this statement will be rolled back, and all the updates will be ignored.
-
as_
(alias_name: Optional[str]) → potc.fixture.imports.FromImport[source]¶ - Overview:
Alias imported item.
- Arguments:
alias_name (
Optional[str]
): Alias name.
- Returns:
self: Self object.
-
import_
(obj_name: str) → potc.fixture.imports.FromImport[source]¶ - Overview:
Import from source.
- Arguments:
obj_name (
str
): Import object name.
- Returns:
self: Self object.
-
property
key
¶ Overview: Key value of the import statement. Used for sorting.
-
property
target
¶ Overview: Import target.
from aa import bb
–> bb.from aa import bb as cc
–> cc.import aa
–> aa.import aa.bb
–> bb.
Just seen target as the actual sign name of the imported object.
DirectImport¶
-
class
potc.fixture.imports.
DirectImport
(_import: str, _as: Optional[str] = None)[source]¶ - Overview:
import xxx as yyy
formatted import statement.
-
__init__
(_import: str, _as: Optional[str] = None)[source]¶ - Overview:
Constructor of
DirectImport
.- Arguments:
_import (
Optional[str]
): Import item, default isNone
._as (
Optional[str]
): Alias name, default isNone
which means no alias.
-
__repr__
() → str¶ - Overview:
Get representation format.
- Returns:
repr (
str
): Representation format.
-
__str__
() → str¶ - Overview:
Get string format, will check its validity before return.
- Returns:
str (
str
): String format.
-
_check_valid
()¶ - Overview:
Check if this statement is valid. if not valid, raise
ValueError
.
-
_is_valid
()[source]¶ - Overview:
Whether this import statement is valid.
- Return:
valid (
bool
): Is valid or not.
-
_with_check
()¶ - Overview:
Open a context, do some update and make sure the final statement is valid. If not, this statement will be rolled back, and all the updates will be ignored.
-
as_
(alias_name: Optional[str]) → potc.fixture.imports.DirectImport[source]¶ - Overview:
Alias imported item.
- Arguments:
alias_name (
Optional[str]
): Alias name.
- Returns:
self: Self object.
-
property
key
¶ Overview: Key value of the import statement. Used for sorting.
-
property
target
¶ Overview: Import target.
from aa import bb
–> bb.from aa import bb as cc
–> cc.import aa
–> aa.import aa.bb
–> bb.
Just seen target as the actual sign name of the imported object.
ImportPool¶
-
class
potc.fixture.imports.
ImportPool
(*imports: potc.fixture.imports.ImportStatement)[source]¶ - Overview:
Pool of import statements.
-
__init__
(*imports: potc.fixture.imports.ImportStatement)[source]¶ - Overview:
Constructor of
ImportPool
.- Arguments:
imports: Import statements.
-
append
(import_: potc.fixture.imports.ImportStatement)[source]¶ - Overview:
Append new statement.
- Arguments:
import_: Import statement.
-
from_
(_from: str) → potc.fixture.imports._SelfFormImport[source]¶ - Overview:
Start a from import statement.
- Arguments:
from (
str
): Import source.
- Returns:
statement (
FromImport
): From import statement.
-
import_
(_import: str) → potc.fixture.imports._SelfDirectImport[source]¶ - Overview:
Start a direct import statement.
- Arguments:
_import (
str
): Import item.
- Returns:
statement (
DirectImport
): Direct import statement.
-
property
imports
¶ - Overview:
Get tuple of current import statements.
- Returns:
imports (
Tuple['ImportStatement', ...]
): Import statements.