summaryrefslogtreecommitdiffstats
path: root/Lib/operator.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-04-29 16:30:48 (GMT)
committerGitHub <noreply@github.com>2024-04-29 16:30:48 (GMT)
commit444ac0b7a64ff6b6caba9c2731bd33151ce18ad1 (patch)
tree572fd300a05e5a177da821c2afc371e3d2122f4a /Lib/operator.py
parent51c70de998ead35674bf4b2b236e9ce8e89d17b4 (diff)
downloadcpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.zip
cpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.tar.gz
cpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.tar.bz2
gh-118285: Fix signatures of operator.{attrgetter,itemgetter,methodcaller} instances (GH-118316)
* Allow to specify the signature of custom callable instances of extension type by the __text_signature__ attribute. * Specify signatures of operator.attrgetter, operator.itemgetter, and operator.methodcaller instances.
Diffstat (limited to 'Lib/operator.py')
-rw-r--r--Lib/operator.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/operator.py b/Lib/operator.py
index 30116c1..02ccdaa 100644
--- a/Lib/operator.py
+++ b/Lib/operator.py
@@ -239,7 +239,7 @@ class attrgetter:
"""
__slots__ = ('_attrs', '_call')
- def __init__(self, attr, *attrs):
+ def __init__(self, attr, /, *attrs):
if not attrs:
if not isinstance(attr, str):
raise TypeError('attribute name must be a string')
@@ -257,7 +257,7 @@ class attrgetter:
return tuple(getter(obj) for getter in getters)
self._call = func
- def __call__(self, obj):
+ def __call__(self, obj, /):
return self._call(obj)
def __repr__(self):
@@ -276,7 +276,7 @@ class itemgetter:
"""
__slots__ = ('_items', '_call')
- def __init__(self, item, *items):
+ def __init__(self, item, /, *items):
if not items:
self._items = (item,)
def func(obj):
@@ -288,7 +288,7 @@ class itemgetter:
return tuple(obj[i] for i in items)
self._call = func
- def __call__(self, obj):
+ def __call__(self, obj, /):
return self._call(obj)
def __repr__(self):
@@ -315,7 +315,7 @@ class methodcaller:
self._args = args
self._kwargs = kwargs
- def __call__(self, obj):
+ def __call__(self, obj, /):
return getattr(obj, self._name)(*self._args, **self._kwargs)
def __repr__(self):