def substitute_pz_in_autodoc_docstring(app, what, name, obj, options, lines):
  """Rewrites docstrings for objects defined in `penzai.pz` to add alias links."""
  del app, what, options
  if (
      name.startswith("penzai.pz")
      or name.startswith("penzai.experimental.v2.pz")
      or name.startswith("penzai.deprecated.v1.pz")
  ):
    if not lines:
      lines.append("")
    alias = canonical_aliases.lookup_alias(obj)
    if alias is not None:
      lines[0] = f"*Alias of* :obj:`{str(alias)}`: " + lines[0]
Rewrites docstrings for objects defined in `penzai.pz` to add alias links.
docs/ext/pz_alias_rewrite.py