pluggy icon indicating copy to clipboard operation
pluggy copied to clipboard

Proposed fix for issue #358

Open eachimei opened this issue 3 years ago • 1 comments

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.

eachimei avatar Aug 03 '22 06:08 eachimei

That's great, thank you 😊

eachimei avatar Aug 03 '22 09:08 eachimei

@eachimei can you please rebase this over main? It should run cleanly now.

nicoddemus avatar Nov 06 '22 11:11 nicoddemus

@eachimei can you please rebase this over main? It should run cleanly now. @nicoddemus , I rebased so we have fresh results now

eachimei avatar Nov 06 '22 12:11 eachimei

Thanks @eachimei!

@RonnyPfannschmidt is this good to merge now?

nicoddemus avatar Nov 06 '22 12:11 nicoddemus

It seems like we didn't install pre-commit here as well, the lint fail is from that, so lint fix needed

RonnyPfannschmidt avatar Nov 06 '22 13:11 RonnyPfannschmidt

Enabled pre-commit for pluggy. 👍

nicoddemus avatar Nov 06 '22 14:11 nicoddemus

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 avatar Nov 06 '22 15:11 nicoddemus

@nicoddemus can you please retry? It had the "allow edit" setting set to "false", it should work now

eachimei avatar Nov 06 '22 15:11 eachimei

Yeah now it works. 👍

nicoddemus avatar Nov 06 '22 16:11 nicoddemus