class documentation

Class representing an ast.Module node.

>>> import astroid
>>> node = astroid.extract_node('import astroid')
>>> node
<Import l.1 at 0x7f23b2e4e5c0>
>>> node.parent
<Module l.0 at 0x7f23b2e4eda0>
Method __init__ No summary
Method absolute_import_activated Whether PEP 328 absolute import behaviour has been enabled.
Method block_range Get a range from where this node starts to where this node ends.
Method bool_value Determine the boolean value of this node.
Method display_type A human readable type of this node.
Method frame The node's frame node.
Method fully_defined Check if this module has been build from a .py file.
Method get_children Undocumented
Method getattr Undocumented
Method igetattr Infer the possible values of the given variable.
Method import_module Get the ast for a given module as if imported from this module.
Method next_sibling The next sibling statement node.
Method postinit Do some setup after initialisation.
Method previous_sibling The previous sibling statement.
Method public_names The list of the names that are publicly available in this module.
Method pytype Get the name of the type that this node represents.
Method relative_to_absolute_name Get the absolute module name for a relative import.
Method scope_lookup Lookup where the given variable is assigned.
Method statement The first parent node, including self, marked as statement node.
Method stream Get a stream to the underlying file or bytes.
Method wildcard_import_names The list of imported names when this module is 'wildcard imported'.
Class Variable col_offset Undocumented
Class Variable end_col_offset Undocumented
Class Variable end_lineno Undocumented
Class Variable file_bytes The string/bytes that this ast was built from.
Class Variable file_encoding The encoding of the source file.
Class Variable fromlineno The first line that this node appears on in the source code.
Class Variable lineno The line that this node appears on in the source code.
Class Variable parent Undocumented
Class Variable scope_attrs The names of module attributes available through the global scope.
Class Variable special_attributes The names of special attributes that this module has.
Instance Variable body The contents of the module.
Instance Variable doc Undocumented
Instance Variable file The path to the file that this ast has been extracted from.
Instance Variable future_imports The imports from __future__.
Instance Variable globals A map of the name of a local variable to the node defining the local.
Instance Variable locals A map of the name of a local variable to the node defining the local.
Instance Variable name The name of the module.
Instance Variable package Whether the node represents a package or a module.
Instance Variable path Undocumented
Instance Variable pure_python Whether the ast was built from source.
Method _get_stream Undocumented
Class Variable _absolute_import_activated Undocumented
Class Variable _astroid_fields Undocumented
Class Variable _other_fields Undocumented
Class Variable _other_other_fields Undocumented

Inherited from LocalsDictNodeNG:

Method __contains__ Check if a local is defined in this scope.
Method __getitem__ The first node the defines the given local.
Method __iter__ Iterate over the names of locals defined in this scoped node.
Method add_local_node Append a child that should alter the locals of this scope node.
Method items Get the names of the locals and the node that defines the local.
Method keys The names of locals defined in this scoped node.
Method qname Get the 'qualified' name of the node.
Method scope The first parent node defining a new scope.
Method set_local Define that the given name is declared in the given statement node.
Method values The nodes that define the locals in this scoped node.
Method _append_node append a child, linking it in the tree
Method _scope_lookup XXX method for interfacing the scope lookup

Inherited from LookupMixIn (via LocalsDictNodeNG):

Method ilookup Lookup the inferred values of the given variable.
Method lookup Lookup where the given variable is assigned.
def __init__(self, name, doc, file=None, path: list[str] | None = None, package=None, parent=None, pure_python=True): (source)
Parameters
name:strThe name of the module.
doc:strThe module docstring.
file:str or NoneThe path to the file that this ast has been extracted from.
path:Optional[List[str]]
package:bool or NoneWhether the node represents a package or a module.
parent:NodeNG or NoneThe parent node in the syntax tree.
pure_python:bool or NoneWhether the ast was built from source.
def absolute_import_activated(self): (source)

Whether PEP 328 absolute import behaviour has been enabled.

Returns
boolTrue if PEP 328 has been enabled, False otherwise.
def block_range(self, lineno): (source)

Get a range from where this node starts to where this node ends.

Parameters
lineno:intUnused.
Returns
tuple(int, int)The range of line numbers that this node belongs to.
def bool_value(self, context=None): (source)

Determine the boolean value of this node.

Returns
boolThe boolean value of this node. For a Module this is always True.
def display_type(self): (source)

A human readable type of this node.

Returns
strThe type of this node.
def frame(self: T, *, future: Literal[None, True] = None) -> T: (source)

The node's frame node.

A frame node is a Module, FunctionDef, ClassDef or Lambda.

Returns
TThe node itself.
def fully_defined(self): (source)

Check if this module has been build from a .py file.

If so, the module contains a complete representation, including the code.

Returns
boolTrue if the module has been built from a .py file.
def get_children(self): (source)

Undocumented

def getattr(self, name, context=None, ignore_locals=False): (source)

Undocumented

def igetattr(self, name, context=None): (source)

Infer the possible values of the given variable.

Parameters
name:strThe name of the variable to infer.
contextUndocumented
Returns
iterable(NodeNG) or NoneThe inferred possible values.
def import_module(self, modname, relative_only=False, level=None): (source)

Get the ast for a given module as if imported from this module.

Parameters
modname:strThe name of the module to "import".
relative_only:boolWhether to only consider relative imports.
level:int or NoneThe level of relative import.
Returns
NodeNGThe imported module ast.
def next_sibling(self): (source)

The next sibling statement node.

Returns
NodeNG or NoneThe next sibling statement node.
def postinit(self, body=None): (source)

Do some setup after initialisation.

Parameters
body:list(NodeNG) or NoneThe contents of the module.
def previous_sibling(self): (source)

The previous sibling statement.

Returns
NodeNG or NoneThe previous sibling statement node.
def public_names(self): (source)

The list of the names that are publicly available in this module.

Returns
list(str)The list of public names.
def pytype(self): (source)

Get the name of the type that this node represents.

Returns
strThe name of the type.
def relative_to_absolute_name(self, modname: str, level: int) -> str: (source)

Get the absolute module name for a relative import.

The relative import can be implicit or explicit.

Parameters
modname:strThe module name to convert.
level:intThe level of relative import.
Returns
strThe absolute module name.
Raises
TooManyLevelsErrorWhen the relative import refers to a module too far above this one.
def scope_lookup(self, node, name, offset=0): (source)

Lookup where the given variable is assigned.

Parameters
node:NodeNGThe node to look for assignments up to. Any assignments after the given node are ignored.
name:strThe name of the variable to find assignments for.
offset:intThe line offset to filter statements up to.
Returns
tuple(str, list(NodeNG))This scope node and the list of assignments associated to the given name according to the scope where it has been found (locals, globals or builtin).
@overload
def statement(self, *, future: Literal[None] = ...) -> Module:
@overload
def statement(self, *, future: Literal[True]) -> NoReturn:
(source)

The first parent node, including self, marked as statement node.

When called on a Module with the future parameter this raises an error.

TODO: Deprecate the future parameter and only raise StatementMissing

Raises
StatementMissingIf no self has no parent attribute and future is True
def stream(self): (source)

Get a stream to the underlying file or bytes.

def wildcard_import_names(self): (source)

The list of imported names when this module is 'wildcard imported'.

It doesn't include the '__builtins__' name which is added by the current CPython implementation of wildcard imports.

Returns
list(str)The list of imported names.
col_offset: None = (source)

Undocumented

end_col_offset: None = (source)

Undocumented

end_lineno: None = (source)

Undocumented

file_bytes = (source)

The string/bytes that this ast was built from.

file_encoding = (source)

The encoding of the source file.

This is used to get unicode out of a source file. Python 2 only.

fromlineno: int = (source)

The first line that this node appears on in the source code.

lineno: Literal[0] = (source)

The line that this node appears on in the source code.

parent: None = (source)

Undocumented

scope_attrs: set[str] = (source)

The names of module attributes available through the global scope.

special_attributes = (source)

The names of special attributes that this module has.

The contents of the module.

Undocumented

The path to the file that this ast has been extracted from.

This will be None when the representation has been built from a built-in module.

future_imports = (source)

The imports from __future__.

globals: dict = (source)

A map of the name of a local variable to the node defining the local.

locals: dict = (source)

A map of the name of a local variable to the node defining the local.

The name of the module.

Whether the node represents a package or a module.

Undocumented

pure_python = (source)

Whether the ast was built from source.

def _get_stream(self): (source)

Undocumented

_absolute_import_activated: bool = (source)

Undocumented

_astroid_fields: tuple[str, ...] = (source)

Undocumented

_other_fields: tuple[str, ...] = (source)

Undocumented

_other_other_fields: tuple[str, ...] = (source)

Undocumented