LocalNamePath#
- class treescope.canonical_aliases.LocalNamePath[source]#
Bases:
object
Expected path where we can find a particular object in a local scope.
The “local scope” can be any dictionary of values with string keys, but it is usually either the locals() or globals() for a particular scope (or the union of these). A local name path is only valid relative to a particular scope that was used to create it.
- Variables:
Methods
__init__
(local_name, attribute_path)retrieve
(local_scope[, forgiving])Retrieves the object at this path.
Attributes
local_name
attribute_path
- retrieve(local_scope: dict[str, Any], forgiving: bool = False) Any [source]#
Retrieves the object at this path.
- Parameters:
local_scope – The scope in which we should retrieve this value.
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:
KeyError, AttributeError – If the object wasn’t found and
forgiving
is False.