@@ -1381,7 +1381,7 @@ def convert(name, locals=locals,
13811381 specs .append (formatvarkw (varkw ) + formatvalue (locals [varkw ]))
13821382 return '(' + ', ' .join (specs ) + ')'
13831383
1384- def _missing_arguments (f_name , argnames , pos , values ):
1384+ def _missing_arguments (f_name , argnames , pos , values , * , has_posonly = False ):
13851385 names = [repr (name ) for name in argnames if name not in values ]
13861386 missing = len (names )
13871387 if missing == 1 :
@@ -1392,10 +1392,18 @@ def _missing_arguments(f_name, argnames, pos, values):
13921392 tail = ", {} and {}" .format (* names [- 2 :])
13931393 del names [- 2 :]
13941394 s = ", " .join (names ) + tail
1395- raise TypeError ("%s() missing %i required %s argument%s: %s" %
1396- (f_name , missing ,
1397- "positional" if pos else "keyword-only" ,
1398- "" if missing == 1 else "s" , s ))
1395+
1396+ if pos :
1397+ qualifier = "positional" if has_posonly else ""
1398+ else :
1399+ qualifier = "keyword-only"
1400+ if qualifier :
1401+ raise TypeError ("%s() missing %i required %s argument%s: %s" %
1402+ (f_name , missing , qualifier ,
1403+ "" if missing == 1 else "s" , s ))
1404+ else :
1405+ raise TypeError ("%s() missing %i required argument%s: %s" %
1406+ (f_name , missing , "" if missing == 1 else "s" , s ))
13991407
14001408def _too_many (f_name , args , kwonly , varargs , defcount , given , values ):
14011409 atleast = len (args ) - defcount
@@ -1429,7 +1437,9 @@ def getcallargs(func, /, *positional, **named):
14291437 f_name = func .__name__
14301438 arg2value = {}
14311439
1432-
1440+ num_posonly = 0
1441+ if hasattr (func , '__code__' ):
1442+ num_posonly = func .__code__ .co_posonlyargcount
14331443 if ismethod (func ) and func .__self__ is not None :
14341444 # implicit 'self' (or 'cls' for classmethods) argument
14351445 positional = (func .__self__ ,) + positional
@@ -1463,7 +1473,9 @@ def getcallargs(func, /, *positional, **named):
14631473 req = args [:num_args - num_defaults ]
14641474 for arg in req :
14651475 if arg not in arg2value :
1466- _missing_arguments (f_name , req , True , arg2value )
1476+ missing_posonly = any (i < num_posonly for i , name in enumerate (args )
1477+ if name in req and name not in arg2value )
1478+ _missing_arguments (f_name , req , True , arg2value , has_posonly = missing_posonly )
14671479 for i , arg in enumerate (args [num_args - num_defaults :]):
14681480 if arg not in arg2value :
14691481 arg2value [arg ] = defaults [i ]
@@ -1475,7 +1487,7 @@ def getcallargs(func, /, *positional, **named):
14751487 else :
14761488 missing += 1
14771489 if missing :
1478- _missing_arguments (f_name , kwonlyargs , False , arg2value )
1490+ _missing_arguments (f_name , kwonlyargs , False , arg2value , has_posonly = False )
14791491 return arg2value
14801492
14811493ClosureVars = namedtuple ('ClosureVars' , 'nonlocals globals builtins unbound' )
0 commit comments