'a': 1}) Fallbacks.from_dict({
Fallbacks()
for aliasing items to import similar to item as alias
/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Attributes
else: warn(msg)
ImpItem (item:str='')
A class to represent an item in the import specification.
Fallbacks ()
for reducing code reuse
BaseImp (namespace:Dict[str,Any]=<factory>)
Import Module class.
This class facilitates dynamic import of modules and their attributes.
ImpSubSpec (name:str, stub:str, items:Optional[List[ForwardRef('ImpItem')]]=<factory>, fallba cks:Union[ForwardRef('Fallbacks'),Dict[str,Any],NoneType]=<fa ctory>, namespace:Dict[str,Any]=<factory>)
A class to represent a sub-specification of the import.
ImpSubSpec(name='rich', stub='tree', items=[ImpItem(name='Tree', nick='rich_tree')])
ImpSubSpec(name='rich', stub='', items=[ImpItem(name='get_console', nick='')])
ImpSpec (name:str, nick:Optional[str]=None, lazy:Optional[bool]=True, subspecs:Optional[List[ForwardRef('ImpSubSpec')]]=<factory>, fal lbacks:Union[ForwardRef('Fallbacks'),Dict[str,Any],NoneType]=<fa ctory>, namespace:Dict[str,Any]=<factory>)
A class to represent an import specification.
/opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Methods
else: warn(msg)
Imp (name:str, nick:Optional[str]=None, subspecs:Optional[List[__main__.ImpSubSpec]]=<factory>, fallbacks:Optional[Dict[str,Any]]=<factory>, lazy:Optional[bool]=True, delay:Optional[bool]=False, namespace:Dict[str,Any]=<factory>, _squash_name_errors:Optional[bool]=True, _reload:Optional[bool]=False)
Import Module class.
This class facilitates dynamic import of modules and their attributes.
Type | Default | Details | |
---|---|---|---|
name | str | The name of the module to import. | |
nick | Optional | None | The alias of the module to import. |
subspecs | Optional | A list of ImpSubSpec objects representing additional specifications for import. |
|
fallbacks | Optional | A dictionary of fallback values for import failures. | |
lazy | Optional | True | Whether or not to use lazy import. |
delay | Optional | False | |
namespace | Dict | ||
_squash_name_errors | Optional | True | |
_reload | Optional | False |
imp_rich = Imp(
'rich', 'rc',
subspecs=[
ImpSubSpec.from_str('from rich.tree import Tree as rich_tree'),
ImpSubSpec.from_str('from rich.text import Text'),
ImpSubSpec.from_str('from rich.markup import espace'),
ImpSubSpec.from_str('from rich.filesize import decimal'),
ImpSubSpec.from_str('from rich.filesize import Console'),
ImpSubSpec.from_str('from rich.progress import Progress'),
# ImpSubSpec.from_str('from rich import get_console')
ImpSubSpec('rich', '', [ImpItem('get_console')])
],
fallbacks={
'rich_tree': Any,
'Text': Any,
},
delay=True,
)
Imp(name='rich', nick='rc', lazy=True, delay=True, _squash_name_errors=True, _reload=False)
# Define a sub specification to import 'sqrt' and 'pi' from 'math' module
subspec = ImpSubSpec('math', '', items=[ImpItem('sqrt'), ImpItem('sqrt')])
subspec
ImpSubSpec(name='math', stub='', items=[ImpItem(name='sqrt', nick=''), ImpItem(name='sqrt', nick='')])