def linkcode_resolve(domain, info):
  """Resolve a GitHub URL corresponding to Python object."""
  if domain != 'py':
    return None

  try:
    mod = sys.modules[info['module']]
  except ImportError:
    return None

  obj = mod
  try:
    for attr in info['fullname'].split('.'):
      obj = getattr(obj, attr)
  except AttributeError:
    return None
  else:
    obj = inspect.unwrap(obj)

  try:
    filename = inspect.getsourcefile(obj)
  except TypeError:
    return None

  try:
    source, lineno = inspect.getsourcelines(obj)
  except OSError:
    return None

  if source_git_hash is not None:
    git_identifier = source_git_hash
  else:
    git_identifier = 'main'
  relpath = os.path.relpath(filename, start=os.path.dirname(penzai.__file__))
  return (
      f'https://github.com/google-deepmind/penzai/blob/{git_identifier}/penzai/'
      f'{relpath}#L{lineno}#L{lineno + len(source) - 1}'
  )
Resolve a GitHub URL corresponding to Python object.
docs/conf.py