mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)
This commit is contained in:
parent
4a686504eb
commit
2085bd0877
34 changed files with 126 additions and 261 deletions
|
@ -1329,14 +1329,12 @@ def _too_many(f_name, args, kwonly, varargs, defcount, given, values):
|
|||
(f_name, sig, "s" if plural else "", given, kwonly_sig,
|
||||
"was" if given == 1 and not kwonly_given else "were"))
|
||||
|
||||
def getcallargs(*func_and_positional, **named):
|
||||
def getcallargs(func, /, *positional, **named):
|
||||
"""Get the mapping of arguments to values.
|
||||
|
||||
A dict is returned, with keys the function argument names (including the
|
||||
names of the * and ** arguments, if any), and values the respective bound
|
||||
values from 'positional' and 'named'."""
|
||||
func = func_and_positional[0]
|
||||
positional = func_and_positional[1:]
|
||||
spec = getfullargspec(func)
|
||||
args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec
|
||||
f_name = func.__name__
|
||||
|
@ -3027,19 +3025,19 @@ class Signature:
|
|||
|
||||
return self._bound_arguments_cls(self, arguments)
|
||||
|
||||
def bind(*args, **kwargs):
|
||||
def bind(self, /, *args, **kwargs):
|
||||
"""Get a BoundArguments object, that maps the passed `args`
|
||||
and `kwargs` to the function's signature. Raises `TypeError`
|
||||
if the passed arguments can not be bound.
|
||||
"""
|
||||
return args[0]._bind(args[1:], kwargs)
|
||||
return self._bind(args, kwargs)
|
||||
|
||||
def bind_partial(*args, **kwargs):
|
||||
def bind_partial(self, /, *args, **kwargs):
|
||||
"""Get a BoundArguments object, that partially maps the
|
||||
passed `args` and `kwargs` to the function's signature.
|
||||
Raises `TypeError` if the passed arguments can not be bound.
|
||||
"""
|
||||
return args[0]._bind(args[1:], kwargs, partial=True)
|
||||
return self._bind(args, kwargs, partial=True)
|
||||
|
||||
def __reduce__(self):
|
||||
return (type(self),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue