Skip to content

Commit

Permalink
pythongh-103406: Modernize pos-only arguments usage in test_signature
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Apr 10, 2023
1 parent ecad802 commit f06ee15
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3044,12 +3044,10 @@ 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)')
Expand Down Expand Up @@ -3556,14 +3554,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 @@ -4157,16 +4150,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

0 comments on commit f06ee15

Please sign in to comment.