summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-06-01 08:00:15 (GMT)
committerGitHub <noreply@github.com>2019-06-01 08:00:15 (GMT)
commit2085bd0877e17ad4d98a4586d5eabb6faecbb190 (patch)
treec25b20d33ebf4d64a28abb8591f4ff7acf90614c /Lib/functools.py
parent4a686504eb2bbf69adf78077458508a7ba131667 (diff)
downloadcpython-2085bd0877e17ad4d98a4586d5eabb6faecbb190.zip
cpython-2085bd0877e17ad4d98a4586d5eabb6faecbb190.tar.gz
cpython-2085bd0877e17ad4d98a4586d5eabb6faecbb190.tar.bz2
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py16
1 files changed, 3 insertions, 13 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 30964a6..64d1201 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -273,15 +273,9 @@ class partial:
__slots__ = "func", "args", "keywords", "__dict__", "__weakref__"
- def __new__(*args, **keywords):
- if not args:
- raise TypeError("descriptor '__new__' of partial needs an argument")
- if len(args) < 2:
- raise TypeError("type 'partial' takes at least one argument")
- cls, func, *args = args
+ def __new__(cls, func, /, *args, **keywords):
if not callable(func):
raise TypeError("the first argument must be callable")
- args = tuple(args)
if hasattr(func, "func"):
args = func.args + args
@@ -295,10 +289,7 @@ class partial:
self.keywords = keywords
return self
- def __call__(*args, **keywords):
- if not args:
- raise TypeError("descriptor '__call__' of partial needs an argument")
- self, *args = args
+ def __call__(self, /, *args, **keywords):
keywords = {**self.keywords, **keywords}
return self.func(*self.args, *args, **keywords)
@@ -402,8 +393,7 @@ class partialmethod(object):
keywords=keywords)
def _make_unbound_method(self):
- def _method(*args, **keywords):
- cls_or_self, *args = args
+ def _method(cls_or_self, /, *args, **keywords):
keywords = {**self.keywords, **keywords}
return self.func(cls_or_self, *self.args, *args, **keywords)
_method.__isabstractmethod__ = self.__isabstractmethod__