lookup_alias

Contents

lookup_alias#

penzai.treescope.canonical_aliases.lookup_alias(the_object: Any, infer_from_attributes: bool = True, allow_outdated: bool = False, allow_relative: bool = False) ModuleAttributePath | LocalNamePath | None[source]#

Retrieves an alias for this object, if possible.

This function checks if an alias has been registered for this object, and also makes sure the object is still available at that alias. It optionally also tries to infer a fallback alias using __module__ and __qualname__ attributes.

Parameters:
  • the_object – Object to get a well-known alias for.

  • infer_from_attributes – Whether to use __module__ and __qualname__ attributes to infer an alias if no explicit path is registered.

  • allow_outdated – If True, return old aliases even if the object is no longer accessible at this path. (For instance, if the module was reloaded after this class/function was defined.)

  • allow_relative – If True, return aliases that are local to the current relative_alias_names context if possible.

Returns:

A path at which we can find this object, or None if we do not have a path for it (or if the path is no longer correct).