AstroidManager

class astroid.manager.AstroidManager[source]

Bases: object

Responsible to build astroid from files or modules.

Use the Borg (singleton) pattern.

property always_load_extensions: bool
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}
property builtins_module: Module
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.

file_from_module_name(modname: str, contextfile: str | None) ModuleSpec[source]
infer_ast_from_something(obj: object, context: InferenceContext | None = None) Iterator[InferenceResult][source]

Infer astroid for the given class.

property max_inferable_values: int
name = 'astroid loader'
property optimize_ast: bool
property prefer_stubs: bool
register_failed_import_hook(hook: Callable[[str], Module]) None[source]

Registers a hook to resolve imports that cannot be found otherwise.

hook must be a function that accepts a single argument modname which contains the name of the module or package that could not be imported. If hook can resolve the import, must return a node of type nodes.Module, otherwise, it must raise AstroidBuildingError.

property register_transform
property unregister_transform
visit_transforms(node: nodes.NodeNG) InferenceResult[source]

Visit the transforms and apply them to the given node.

zip_import_data(filepath: str) Module | None[source]