@@ -2463,18 +2463,43 @@ def test_signature_object(self):
24632463 self .assertEqual (str (S ()), '()' )
24642464 self .assertEqual (repr (S ().parameters ), 'mappingproxy(OrderedDict())' )
24652465
2466- def test (po , pk , pod = 42 , pkd = 100 , * args , ko , ** kwargs ):
2466+ def test (po , / , pk , pkd = 100 , * args , ko , kod = 10 , ** kwargs ):
24672467 pass
2468+
24682469 sig = inspect .signature (test )
2469- po = sig .parameters ['po' ].replace (kind = P .POSITIONAL_ONLY )
2470- pod = sig .parameters ['pod' ].replace (kind = P .POSITIONAL_ONLY )
2470+ self .assertTrue (repr (sig ).startswith ('<Signature' ))
2471+ self .assertTrue ('(po, /, pk' in repr (sig ))
2472+
2473+ # We need two functions, because it is impossible to represent
2474+ # all param kinds in a single one.
2475+ def test2 (pod = 42 , / ):
2476+ pass
2477+
2478+ sig2 = inspect .signature (test2 )
2479+ self .assertTrue (repr (sig2 ).startswith ('<Signature' ))
2480+ self .assertTrue ('(pod=42, /)' in repr (sig2 ))
2481+
2482+ po = sig .parameters ['po' ]
2483+ pod = sig2 .parameters ['pod' ]
24712484 pk = sig .parameters ['pk' ]
24722485 pkd = sig .parameters ['pkd' ]
24732486 args = sig .parameters ['args' ]
24742487 ko = sig .parameters ['ko' ]
2488+ kod = sig .parameters ['kod' ]
24752489 kwargs = sig .parameters ['kwargs' ]
24762490
24772491 S ((po , pk , args , ko , kwargs ))
2492+ S ((po , pk , ko , kod ))
2493+ S ((po , pod , ko ))
2494+ S ((po , pod , kod ))
2495+ S ((pod , ko , kod ))
2496+ S ((pod , kod ))
2497+ S ((pod , args , kod , kwargs ))
2498+ # keyword-only parameters without default values
2499+ # can follow keyword-only parameters with default values:
2500+ S ((kod , ko ))
2501+ S ((kod , ko , kwargs ))
2502+ S ((args , kod , ko ))
24782503
24792504 with self .assertRaisesRegex (ValueError , 'wrong parameter order' ):
24802505 S ((pk , po , args , ko , kwargs ))
@@ -2495,15 +2520,18 @@ def test(po, pk, pod=42, pkd=100, *args, ko, **kwargs):
24952520 with self .assertRaisesRegex (ValueError , 'follows default argument' ):
24962521 S ((pod , po ))
24972522
2523+ with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2524+ S ((pod , pk ))
2525+
2526+ with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2527+ S ((po , pod , pk ))
2528+
24982529 with self .assertRaisesRegex (ValueError , 'follows default argument' ):
24992530 S ((po , pkd , pk ))
25002531
25012532 with self .assertRaisesRegex (ValueError , 'follows default argument' ):
25022533 S ((pkd , pk ))
25032534
2504- self .assertTrue (repr (sig ).startswith ('<Signature' ))
2505- self .assertTrue ('(po, pk' in repr (sig ))
2506-
25072535 def test_signature_object_pickle (self ):
25082536 def foo (a , b , * , c :1 = {}, ** kw ) -> {42 :'ham' }: pass
25092537 foo_partial = functools .partial (foo , a = 1 )
0 commit comments