mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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:
parent
8d8729146f
commit
6587fc60d4
6 changed files with 62 additions and 0 deletions
|
@ -518,6 +518,18 @@ class OperatorTestCase:
|
|||
with self.assertRaises(LookupError):
|
||||
operator.length_hint(X(LookupError))
|
||||
|
||||
def test_call(self):
|
||||
operator = self.module
|
||||
|
||||
def func(*args, **kwargs): return args, kwargs
|
||||
|
||||
self.assertEqual(operator.call(func), ((), {}))
|
||||
self.assertEqual(operator.call(func, 0, 1), ((0, 1), {}))
|
||||
self.assertEqual(operator.call(func, a=2, obj=3),
|
||||
((), {"a": 2, "obj": 3}))
|
||||
self.assertEqual(operator.call(func, 0, 1, a=2, obj=3),
|
||||
((0, 1), {"a": 2, "obj": 3}))
|
||||
|
||||
def test_dunder_is_original(self):
|
||||
operator = self.module
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue