class Module(LocalsDictNodeNG): (source)
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__ |
|
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. |
Parameters | |
name:str | The name of the module. |
doc:str | The module docstring. |
file:str or None | The path to the file that this ast has been extracted from. |
path:Optional[List[str]] | |
package:bool or None | Whether the node represents a package or a module. |
parent:NodeNG or None | The parent node in the syntax tree. |
pure_python:bool or None | Whether the ast was built from source. |
Parameters | |
lineno:int | Unused. |
Returns | |
tuple(int, int) | The range of line numbers that this node belongs to. |
Returns | |
bool | The boolean value of this node.
For a Module this is always True. |
The node's frame node.
A frame node is a Module
, FunctionDef
,
ClassDef
or Lambda
.
Parameters | |
future:Literal[ | Undocumented |
Returns | |
T | The node itself. |
Check if this module has been build from a .py file.
If so, the module contains a complete representation, including the code.
Returns | |
bool | True if the module has been built from a .py file. |
Parameters | |
name:str | The name of the variable to infer. |
context | Undocumented |
Returns | |
iterable(NodeNG) or None | The inferred possible values. |
Parameters | |
modname:str | The name of the module to "import". |
relative_only:bool | Whether to only consider relative imports. |
level:int or None | The level of relative import. |
Returns | |
NodeNG | The imported module ast. |
Returns | |
list(str) | The list of public names. |
Get the absolute module name for a relative import.
The relative import can be implicit or explicit.
Parameters | |
modname:str | The module name to convert. |
level:int | The level of relative import. |
Returns | |
str | The absolute module name. |
Raises | |
TooManyLevelsError | When the relative import refers to a module too far above this one. |
Parameters | |
node:NodeNG | The node to look for assignments up to. Any assignments after the given node are ignored. |
name:str | The name of the variable to find assignments for. |
offset:int | The 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). |
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
Parameters | |
future:Literal[ | Undocumented |
Returns | |
Union[ | Undocumented |
Raises | |
StatementMissing | If no self has no parent attribute and future is True |
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. |
The encoding of the source file.
This is used to get unicode out of a source file. Python 2 only.
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.