bpo-44019: Implement operator.call(). (GH-27888)

Having `operator.call(obj, arg)` mean `type(obj).__call__(obj, arg)` is
consistent with the other dunder operators.  The semantics with `*args,
**kwargs` then follow naturally from the single-arg semantics.
This commit is contained in:
Antony Lee 2021-09-24 17:22:49 +02:00 committed by GitHub
parent 8d8729146f
commit 6587fc60d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 0 deletions

View file

@ -221,6 +221,12 @@ def length_hint(obj, default=0):
raise ValueError(msg)
return val
# Other Operations ************************************************************#
def call(obj, /, *args, **kwargs):
"""Same as obj(*args, **kwargs)."""
return obj(*args, **kwargs)
# Generalized Lookup Objects **************************************************#
class attrgetter:
@ -423,6 +429,7 @@ __not__ = not_
__abs__ = abs
__add__ = add
__and__ = and_
__call__ = call
__floordiv__ = floordiv
__index__ = index
__inv__ = inv