ModuleAttributePath#

class penzai.treescope.canonical_aliases.ModuleAttributePath[source]#

Bases: object

Expected path where we can find a particular object in a module.

Variables:
  • module_name (str) – Fully-qualified name of the module (the key of the module in sys.modules) in which this object can be found.

  • attribute_path (tuple[str, ...]) – Sequence of attributes identifying this object, separated by dots (“.”). For instance, if this is [“foo”, “bar”] then we expect to find the object at “{module_name}.foo.bar”.

Methods

__init__(module_name, attribute_path)

retrieve([forgiving])

Retrieves the object at this path.

Attributes

module_name

attribute_path

retrieve(forgiving: bool = False) Any[source]#

Retrieves the object at this path.

Parameters:

forgiving – If True, return None on failure instead of raising an error.

Returns:

The retrieved object, or None if it wasn’t found and forgiving was True.

Raises:

ValueError – If the object wasn’t found and forgiving is False.