AstroidManager¶
- class astroid.manager.AstroidManager[source]¶
Bases:
objectResponsible to build astroid from files or modules.
Use the Borg (singleton) pattern.
- ast_from_class(klass: type, modname: str | None = None) ClassDef[source]¶
Get astroid for the given class.
- ast_from_file(filepath: str, modname: str | None = None, fallback: bool = True, source: bool = False) Module[source]¶
Given a module name, return the astroid object.
- ast_from_module(module: ModuleType, modname: str | None = None) Module[source]¶
Given an imported module, return the astroid object.
- ast_from_module_name(modname: str | None, context_file: str | None = None, use_cache: bool = True) Module[source]¶
Given a module name, return the astroid object.
- ast_from_string(data: str, modname: str = '', filepath: str | None = None) Module[source]¶
Given some source code as a string, return its corresponding astroid object.
- bootstrap() None[source]¶
Bootstrap the required AST modules needed for the manager to work.
The bootstrap usually involves building the AST for the builtins module, which is required by the rest of astroid to work correctly.
- brain: ClassVar[AstroidManagerBrain] = {'_failed_import_hooks': [<function _import_gi_module>, <function _six_fail_hook>], '_mod_file_cache': {}, '_transform': <astroid.transforms.TransformVisitor object>, 'always_load_extensions': False, 'astroid_cache': {}, 'extension_package_whitelist': {}, 'max_inferable_values': 100, 'module_denylist': {}, 'optimize_ast': False, 'prefer_stubs': False}¶
- cache_module(module: Module) None[source]¶
Cache a module if no module with the same name is known yet.
- clear_cache() None[source]¶
Clear the underlying caches, bootstrap the builtins module and re-register transforms.
- infer_ast_from_something(obj: object, context: InferenceContext | None = None) Iterator[InferenceResult][source]¶
Infer astroid for the given class.
- name = 'astroid loader'¶
- register_failed_import_hook(hook: Callable[[str], Module]) None[source]¶
Registers a hook to resolve imports that cannot be found otherwise.
hookmust be a function that accepts a single argumentmodnamewhich contains the name of the module or package that could not be imported. Ifhookcan resolve the import, must return a node of typenodes.Module, otherwise, it must raiseAstroidBuildingError.
- property register_transform¶
- property unregister_transform¶
- visit_transforms(node: nodes.NodeNG) InferenceResult[source]¶
Visit the transforms and apply them to the given node.