relative_alias_names

relative_alias_names#

penzai.treescope.canonical_aliases.relative_alias_names(relative_scope: ~typing.Mapping[str, ~typing.Any] | ~typing.Literal['magic'], predicate: ~typing.Callable[[~typing.Any, ~penzai.treescope.canonical_aliases.LocalNamePath], bool] = <function default_well_known_filter>) AbstractContextManager[None][source]#

Context manager that makes lookup_alias return relative aliases.

Parameters:
  • relative_scope – A dictionary mapping in-scope names to their values, e.g. globals() or {**globals(), **locals()}. Objects that are reachable from this scope will have aliases that reference the keys in this dict. Alternatively, can be the string “magic”, in which case we will walk the stack and use the {**globals(), **locals()} of the caller. (“magic” is only recommended for interactive usage.)

  • predicate – A filter function to check if an object should be given an alias.

Returns:

A context manager in which lookup_alias will try to return relative aliases when allow_relative=True.