@@ -2301,18 +2301,43 @@ def test_signature_object(self):
2301
2301
self .assertEqual (str (S ()), '()' )
2302
2302
self .assertEqual (repr (S ().parameters ), 'mappingproxy(OrderedDict())' )
2303
2303
2304
- def test (po , pk , pod = 42 , pkd = 100 , * args , ko , ** kwargs ):
2304
+ def test (po , / , pk , pkd = 100 , * args , ko , kod = 10 , ** kwargs ):
2305
2305
pass
2306
+
2306
2307
sig = inspect .signature (test )
2307
- po = sig .parameters ['po' ].replace (kind = P .POSITIONAL_ONLY )
2308
- pod = sig .parameters ['pod' ].replace (kind = P .POSITIONAL_ONLY )
2308
+ self .assertTrue (repr (sig ).startswith ('<Signature' ))
2309
+ self .assertTrue ('(po, /, pk' in repr (sig ))
2310
+
2311
+ # We need two functions, because it is impossible to represent
2312
+ # all param kinds in a single one.
2313
+ def test2 (pod = 42 , / ):
2314
+ pass
2315
+
2316
+ sig2 = inspect .signature (test2 )
2317
+ self .assertTrue (repr (sig2 ).startswith ('<Signature' ))
2318
+ self .assertTrue ('(pod=42, /)' in repr (sig2 ))
2319
+
2320
+ po = sig .parameters ['po' ]
2321
+ pod = sig2 .parameters ['pod' ]
2309
2322
pk = sig .parameters ['pk' ]
2310
2323
pkd = sig .parameters ['pkd' ]
2311
2324
args = sig .parameters ['args' ]
2312
2325
ko = sig .parameters ['ko' ]
2326
+ kod = sig .parameters ['kod' ]
2313
2327
kwargs = sig .parameters ['kwargs' ]
2314
2328
2315
2329
S ((po , pk , args , ko , kwargs ))
2330
+ S ((po , pk , ko , kod ))
2331
+ S ((po , pod , ko ))
2332
+ S ((po , pod , kod ))
2333
+ S ((pod , ko , kod ))
2334
+ S ((pod , kod ))
2335
+ S ((pod , args , kod , kwargs ))
2336
+ # keyword-only parameters without default values
2337
+ # can follow keyword-only parameters with default values:
2338
+ S ((kod , ko ))
2339
+ S ((kod , ko , kwargs ))
2340
+ S ((args , kod , ko ))
2316
2341
2317
2342
with self .assertRaisesRegex (ValueError , 'wrong parameter order' ):
2318
2343
S ((pk , po , args , ko , kwargs ))
@@ -2333,15 +2358,18 @@ def test(po, pk, pod=42, pkd=100, *args, ko, **kwargs):
2333
2358
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2334
2359
S ((pod , po ))
2335
2360
2361
+ with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2362
+ S ((pod , pk ))
2363
+
2364
+ with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2365
+ S ((po , pod , pk ))
2366
+
2336
2367
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2337
2368
S ((po , pkd , pk ))
2338
2369
2339
2370
with self .assertRaisesRegex (ValueError , 'follows default argument' ):
2340
2371
S ((pkd , pk ))
2341
2372
2342
- self .assertTrue (repr (sig ).startswith ('<Signature' ))
2343
- self .assertTrue ('(po, pk' in repr (sig ))
2344
-
2345
2373
def test_signature_object_pickle (self ):
2346
2374
def foo (a , b , * , c :1 = {}, ** kw ) -> {42 :'ham' }: pass
2347
2375
foo_partial = functools .partial (foo , a = 1 )
0 commit comments