Skip to content

Commit a398cf2

Browse files
committed
Merge pull request #9 from mdboom/deprecation-warnings
Use inspect.signature instead of inspect.getargspec
2 parents e802d47 + d6f71fe commit a398cf2

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

pluggy.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,16 @@ class PluginValidationError(Exception):
763763
""" plugin failed validation. """
764764

765765

766-
def _formatdef(func):
767-
return "%s%s" % (
768-
func.__name__,
769-
inspect.formatargspec(*inspect.getargspec(func))
770-
)
766+
767+
if hasattr(inspect, 'signature'):
768+
def _formatdef(func):
769+
return "%s%s" % (
770+
func.__name__,
771+
str(inspect.signature(func))
772+
)
773+
else:
774+
def _formatdef(func):
775+
return "%s%s" % (
776+
func.__name__,
777+
inspect.formatargspec(*inspect.getargspec(func))
778+
)

test_pluggy.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pluggy import (PluginManager, varnames, PluginValidationError,
77
HookimplMarker, HookspecMarker)
88

9-
from pluggy import (_MultiCall, _TagTracer, HookImpl)
9+
from pluggy import (_MultiCall, _TagTracer, HookImpl, _formatdef)
1010

1111
hookspec = HookspecMarker("example")
1212
hookimpl = HookimplMarker("example")
@@ -665,6 +665,21 @@ class D:
665665
assert varnames(D) == ()
666666

667667

668+
def test_formatdef():
669+
def function1(): pass
670+
assert _formatdef(function1) == 'function1()'
671+
672+
def function2(arg1): pass
673+
assert _formatdef(function2) == "function2(arg1)"
674+
675+
def function3(arg1, arg2="qwe"): pass
676+
assert _formatdef(function3) == "function3(arg1, arg2='qwe')"
677+
678+
def function4(arg1, *args, **kwargs): pass
679+
assert _formatdef(function4) == "function4(arg1, *args, **kwargs)"
680+
681+
682+
668683
class Test_MultiCall:
669684
def test_uses_copy_of_methods(self):
670685
l = [lambda: 42]

0 commit comments

Comments
 (0)