@@ -2463,18 +2463,43 @@ def test_signature_object(self):
2463
2463
self .assertEqual (str (S ()), '()' )
2464
2464
self .assertEqual (repr (S ().parameters ), 'mappingproxy(OrderedDict())' )
2465
2465
2466
- def test (po , pk , pod = 42 , pkd = 100 , * args , ko , ** kwargs ):
2466
+ def test (po , / , pk , pkd = 100 , * args , ko , kod = 10 , ** kwargs ):
2467
2467
pass
2468
+
2468
2469
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' ]
2471
2484
pk = sig .parameters ['pk' ]
2472
2485
pkd = sig .parameters ['pkd' ]
2473
2486
args = sig .parameters ['args' ]
2474
2487
ko = sig .parameters ['ko' ]
2488
+ kod = sig .parameters ['kod' ]
2475
2489
kwargs = sig .parameters ['kwargs' ]
2476
2490
2477
2491
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 ))
2478
2503
2479
2504
with self .assertRaisesRegex (ValueError , 'wrong parameter order' ):
2480
2505
S ((pk , po , args , ko , kwargs ))
@@ -2495,15 +2520,18 @@ def test(po, pk, pod=42, pkd=100, *args, ko, **kwargs):
2495
2520
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2496
2521
S ((pod , po ))
2497
2522
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
+
2498
2529
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2499
2530
S ((po , pkd , pk ))
2500
2531
2501
2532
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2502
2533
S ((pkd , pk ))
2503
2534
2504
- self .assertTrue (repr (sig ).startswith ('<Signature' ))
2505
- self .assertTrue ('(po, pk' in repr (sig ))
2506
-
2507
2535
def test_signature_object_pickle (self ):
2508
2536
def foo (a , b , * , c :1 = {}, ** kw ) -> {42 :'ham' }: pass
2509
2537
foo_partial = functools .partial (foo , a = 1 )
0 commit comments