Proposed fix for issue #358
Switch to inspect.signature instead of inspect.getfullargspec to properly support wrapper chains (decorated functions) - see details in issue #358 .
In the proposed change I tried to do the minimal required changes to varnames.
That's great, thank you 😊
@eachimei can you please rebase this over main? It should run cleanly now.
@eachimei can you please rebase this over
main? It should run cleanly now. @nicoddemus , I rebased so we have fresh results now
Thanks @eachimei!
@RonnyPfannschmidt is this good to merge now?
It seems like we didn't install pre-commit here as well, the lint fail is from that, so lint fix needed
Enabled pre-commit for pluggy. 👍
I did fix it locally but unfortunately I cannot push to eachimei:main (permission denied), here's the diff:
diff --git a/src/pluggy/_hooks.py b/src/pluggy/_hooks.py
index d376eca..73f0e80 100644
--- a/src/pluggy/_hooks.py
+++ b/src/pluggy/_hooks.py
@@ -244,8 +244,11 @@ def varnames(func: object) -> Tuple[Tuple[str, ...], Tuple[str, ...]]:
except Exception:
return (), ()
- try: # func MUST be a function or method here or we won't parse any args
- sig = inspect.signature(func.__func__ if inspect.ismethod(func) else func)
+ try:
+ # func MUST be a function or method here or we won't parse any args.
+ sig = inspect.signature(
+ func.__func__ if inspect.ismethod(func) else func # type:ignore[arg-type]
+ )
except TypeError:
return (), ()
diff --git a/testing/test_helpers.py b/testing/test_helpers.py
index d7ec6ce..4ddd945 100644
--- a/testing/test_helpers.py
+++ b/testing/test_helpers.py
@@ -87,12 +87,13 @@ def test_formatdef() -> None:
def test_varnames_decorator() -> None:
- F = TypeVar('F', bound=Callable[..., Any])
+ F = TypeVar("F", bound=Callable[..., Any])
def my_decorator(func: F) -> F:
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
+
return cast(F, wrapper)
@my_decorator
@nicoddemus can you please retry? It had the "allow edit" setting set to "false", it should work now
Yeah now it works. 👍