autodoc2.astroid_utils
#
Utilities for working with astroid nodes.
Module Contents#
Functions#
Resolve a name from an aliased import to its original name. |
|
Check if the function is a constructor. |
|
Get the full path of a name from a |
|
Get the name and value of the assignment of the given node. |
|
Get the value of a constant node. |
|
Get the type annotation of the assignment of the given node. |
|
Resolve a type annotation to a string. |
|
Resolve where a node is defined to get its fully qualified name. |
|
Get the contents of the |
|
Check if the function is decorated as a singledispatch. |
|
Check if the decorator is a singledispatch. |
|
Check if the function is decorated as a singledispatch register. |
|
Check if the function is decorated as a property. |
|
Check if the decorator is a property. |
|
Check if the function is decorated as a property setter. |
|
Get the docstring of a node, using a parent docstring if needed. |
|
Check if a class is an exception. |
|
Check if the function is decorated as an overload definition. |
|
Get the docstring of a node, using a parent docstring if needed. |
|
Get the return annotation of a node. |
|
Get the arguments of a function. |
|
Iterate over arguments. |
|
API#
- autodoc2.astroid_utils.resolve_import_alias(name: str, import_names: list[tuple[str, str | None]]) str [source]#
Resolve a name from an aliased import to its original name.
- Parameters:
name – The potentially aliased name to resolve.
import_names – The pairs of original names and aliases from the import.
- Returns:
The original name.
- autodoc2.astroid_utils.is_constructor(node: astroid.nodes.NodeNG) bool [source]#
Check if the function is a constructor.
- autodoc2.astroid_utils.get_full_import_name(import_from: astroid.nodes.ImportFrom, name: str) str [source]#
Get the full path of a name from a
from x import y
statement.- Returns:
The full import path of the name.
- autodoc2.astroid_utils.get_assign_value(node: astroid.nodes.NodeNG) None | tuple[str, Any] [source]#
Get the name and value of the assignment of the given node.
Assignments to multiple names are ignored, as per PEP 257.
- Parameters:
node – The node to get the assignment value from.
- Returns:
The name that is assigned to, and the value assigned to the name (if it can be converted).
- autodoc2.astroid_utils.get_const_values(node: astroid.nodes.NodeNG) Any [source]#
Get the value of a constant node.
- autodoc2.astroid_utils.get_assign_annotation(node: astroid.nodes.Assign) None | str [source]#
Get the type annotation of the assignment of the given node.
- Returns:
The type annotation as a string, or None if one does not exist.
- autodoc2.astroid_utils.resolve_annotation(annotation: astroid.nodes.NodeNG) str [source]#
Resolve a type annotation to a string.
- autodoc2.astroid_utils.resolve_qualname(node: astroid.nodes.NodeNG, basename: str) str [source]#
Resolve where a node is defined to get its fully qualified name.
- Parameters:
node – The node representing the base name.
basename – The partial base name to resolve.
- Returns:
The fully resolved base name.
- autodoc2.astroid_utils.get_module_all(node: astroid.nodes.Module) None | list[str] [source]#
Get the contents of the
__all__
variable from a module.
- autodoc2.astroid_utils.is_decorated_with_singledispatch(node: astroid.nodes.FunctionDef | astroid.nodes.AsyncFunctionDef) bool [source]#
Check if the function is decorated as a singledispatch.
- autodoc2.astroid_utils.is_singledispatch_decorator(decorator: astroid.Name) bool [source]#
Check if the decorator is a singledispatch.
- autodoc2.astroid_utils.is_decorated_as_singledispatch_register(node: astroid.nodes.FunctionDef | astroid.nodes.AsyncFunctionDef) bool [source]#
Check if the function is decorated as a singledispatch register.
- autodoc2.astroid_utils.is_decorated_with_property(node: astroid.nodes.FunctionDef | astroid.nodes.AsyncFunctionDef) bool [source]#
Check if the function is decorated as a property.
- autodoc2.astroid_utils.is_property_decorator(decorator: astroid.Name) bool [source]#
Check if the decorator is a property.
- autodoc2.astroid_utils.is_decorated_with_property_setter(node: astroid.nodes.FunctionDef | astroid.nodes.AsyncFunctionDef) bool [source]#
Check if the function is decorated as a property setter.
- Parameters:
node – The node to check.
- Returns:
True if the function is a property setter, False otherwise.
- autodoc2.astroid_utils.get_class_docstring(node: astroid.nodes.ClassDef) tuple[str, str | None] [source]#
Get the docstring of a node, using a parent docstring if needed.
- autodoc2.astroid_utils.is_exception(node: astroid.nodes.ClassDef) bool [source]#
Check if a class is an exception.
- autodoc2.astroid_utils.is_decorated_with_overload(node: astroid.nodes.FunctionDef) bool [source]#
Check if the function is decorated as an overload definition.
- autodoc2.astroid_utils.is_overload_decorator(decorator: astroid.Name | astroid.Attribute) bool [source]#
- autodoc2.astroid_utils.get_func_docstring(node: astroid.nodes.FunctionDef) tuple[str, None | str] [source]#
Get the docstring of a node, using a parent docstring if needed.
- autodoc2.astroid_utils.get_return_annotation(node: astroid.nodes.FunctionDef) None | str [source]#
Get the return annotation of a node.
- autodoc2.astroid_utils.get_args_info(args_node: astroid.Arguments) list[tuple[None | str, None | str, None | str, None | str]] [source]#
Get the arguments of a function.
- Returns:
a list of (type, name, annotation, default)
- autodoc2.astroid_utils._iter_args(args: list[astroid.nodes.NodeNG], annotations: list[astroid.nodes.NodeNG], defaults: list[astroid.nodes.NodeNG]) Iterable[tuple[str, None | str, str | None]] [source]#
Iterate over arguments.