autodoc2.astroid_utils#

Utilities for working with astroid nodes.

Module Contents#

Functions#

resolve_import_alias

Resolve a name from an aliased import to its original name.

is_constructor

Check if the function is a constructor.

get_full_import_name

Get the full path of a name from a from x import y statement.

get_assign_value

Get the name and value of the assignment of the given node.

get_const_values

Get the value of a constant node.

get_assign_annotation

Get the type annotation of the assignment of the given node.

resolve_annotation

Resolve a type annotation to a string.

resolve_qualname

Resolve where a node is defined to get its fully qualified name.

get_module_all

Get the contents of the __all__ variable from a module.

is_decorated_with_singledispatch

Check if the function is decorated as a singledispatch.

is_singledispatch_decorator

Check if the decorator is a singledispatch.

is_decorated_as_singledispatch_register

Check if the function is decorated as a singledispatch register.

is_decorated_with_property

Check if the function is decorated as a property.

is_property_decorator

Check if the decorator is a property.

is_decorated_with_property_setter

Check if the function is decorated as a property setter.

get_class_docstring

Get the docstring of a node, using a parent docstring if needed.

is_exception

Check if a class is an exception.

is_decorated_with_overload

Check if the function is decorated as an overload definition.

is_overload_decorator

get_func_docstring

Get the docstring of a node, using a parent docstring if needed.

get_return_annotation

Get the return annotation of a node.

get_args_info

Get the arguments of a function.

_iter_args

Iterate over arguments.

_merge_annotations

_is_ellipsis

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.

autodoc2.astroid_utils._merge_annotations(annotations: Iterable[Any], comment_annotations: Iterable[Any]) Iterable[Any][source]#
autodoc2.astroid_utils._is_ellipsis(node: Any) bool[source]#