Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3044,14 +3044,9 @@ def foo(a=1, b=2, c=3):
self.assertEqual(_foo(*ba.args, **ba.kwargs), (12, 10, 20))


def foo(a, b, c, d, **kwargs):
def foo(a, b, /, c, d, **kwargs):
pass
sig = inspect.signature(foo)
params = sig.parameters.copy()
params['a'] = params['a'].replace(kind=Parameter.POSITIONAL_ONLY)
params['b'] = params['b'].replace(kind=Parameter.POSITIONAL_ONLY)
foo.__signature__ = inspect.Signature(params.values())
sig = inspect.signature(foo)
self.assertEqual(str(sig), '(a, b, /, c, d, **kwargs)')

self.assertEqual(self.signature(partial(foo, 1)),
Expand Down Expand Up @@ -3556,14 +3551,9 @@ def test_signature_str_positional_only(self):
P = inspect.Parameter
S = inspect.Signature

def test(a_po, *, b, **kwargs):
def test(a_po, /, *, b, **kwargs):
return a_po, kwargs

sig = inspect.signature(test)
new_params = list(sig.parameters.values())
new_params[0] = new_params[0].replace(kind=P.POSITIONAL_ONLY)
test.__signature__ = sig.replace(parameters=new_params)

self.assertEqual(str(inspect.signature(test)),
'(a_po, /, *, b, **kwargs)')

Expand Down Expand Up @@ -3593,6 +3583,14 @@ def test() -> 42:
self.assertEqual(sig.return_annotation, 42)
self.assertEqual(sig, inspect.signature(test))

def test_signature_replaced(self):
def test():
pass

spam_param = inspect.Parameter('spam', inspect.Parameter.POSITIONAL_ONLY)
sig = test.__signature__ = inspect.Signature(parameters=(spam_param,))
self.assertEqual(sig, inspect.signature(test))

def test_signature_on_mangled_parameters(self):
class Spam:
def foo(self, __p1:1=2, *, __p2:2=3):
Expand Down Expand Up @@ -4157,16 +4155,9 @@ def test(a, *args, b, z=100, **kwargs):
def test_signature_bind_positional_only(self):
P = inspect.Parameter

def test(a_po, b_po, c_po=3, foo=42, *, bar=50, **kwargs):
def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
return a_po, b_po, c_po, foo, bar, kwargs

sig = inspect.signature(test)
new_params = collections.OrderedDict(tuple(sig.parameters.items()))
for name in ('a_po', 'b_po', 'c_po'):
new_params[name] = new_params[name].replace(kind=P.POSITIONAL_ONLY)
new_sig = sig.replace(parameters=new_params.values())
test.__signature__ = new_sig

self.assertEqual(self.call(test, 1, 2, 4, 5, bar=6),
(1, 2, 4, 5, 6, {}))

Expand Down