pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.12k stars 145 forks source link

setting `git_link_template` causes failures on `property` and `cached_property` #450

Open mivanit opened 3 weeks ago

mivanit commented 3 weeks ago

Expected Behavior

pdoc should successfully build docs with git_link_template = 'https://github.com/USER/PROJECT/blob/{commit}/{path}#L{start_line}-L{end_line}' for classes with property or cached_property

Actual Behavior

Python/Lib/site-packages/pdoc/html_helpers.py:580: UserWarning: format_git_link for <functools.cached_property object at ...> failed:
Traceback (most recent call last):
  File "Python/Lib/site-packages/pdoc/html_helpers.py", line 567, in format_git_link
    abs_path = inspect.getfile(inspect.unwrap(dobj.obj))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "Python/Lib/inspect.py", line 929, in getfile
    raise TypeError('module, class, method, function, traceback, frame, or '
TypeError: module, class, method, function, traceback, frame, or code object was expected, got cached_property

  warn(f'format_git_link for {dobj.obj} failed:\n{traceback.format_exc()}')

Steps to Reproduce

  1. create a python module with a class with a property or cached_property
  2. create a config.mako with git_link_template not None
  3. run pdoc on the module with the config.mako in the templates dir

Additional info