Skip to content

Commit

Permalink
get source_file of wrapped functions (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyier committed Jan 17, 2024
1 parent 8c15000 commit 8750631
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Unreleased: pdoc next

- pdoc now correctly extracts the source_file of wrapped functions.
([#657](https://github.com/mitmproxy/pdoc/pull/657), @tmeyier)

## 2023-12-22: pdoc 14.3.0

Expand Down
2 changes: 2 additions & 0 deletions pdoc/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ def __init__(
unwrapped = func.__func__ # type: ignore
elif isinstance(func, singledispatchmethod):
unwrapped = func.func # type: ignore
elif hasattr(func, "__wrapped__"):
unwrapped = func.__wrapped__
else:
unwrapped = func
super().__init__(modulename, qualname, unwrapped, taken_from)
Expand Down
10 changes: 10 additions & 0 deletions test/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,13 @@ def test_default_value_masks_env_vars(monkeypatch):
assert v2.default_value_str == "'42.0.1'"
finally:
_environ_lookup.cache_clear()


def test_source_file_method():
mod = extract.load_module(extract.parse_spec(here / "testdata" / "demo_long.py"))

m = Module(mod)

assert m.members["Foo"].members["a_cached_function"].source_file == (
here / "testdata" / "demo_long.py"
)

0 comments on commit 8750631

Please sign in to comment.