From 8750631893d50c3b26da69d125476ffba205a98b Mon Sep 17 00:00:00 2001 From: tmeyier <95271082+tmeyier@users.noreply.github.com> Date: Wed, 17 Jan 2024 22:03:43 +0100 Subject: [PATCH] get source_file of wrapped functions (#657) --- CHANGELOG.md | 2 ++ pdoc/doc.py | 2 ++ test/test_doc.py | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f07fc5b2..85737ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pdoc/doc.py b/pdoc/doc.py index e89d7f28..a415c841 100644 --- a/pdoc/doc.py +++ b/pdoc/doc.py @@ -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) diff --git a/test/test_doc.py b/test/test_doc.py index 98208460..4df81d6f 100644 --- a/test/test_doc.py +++ b/test/test_doc.py @@ -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" + )