From 72c359912d36705a94fca8b63d80451905a14ae4 Mon Sep 17 00:00:00 2001 From: blhsing Date: Wed, 11 Sep 2019 07:28:06 -0700 Subject: bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable * 📜🤖 Added by blurb_it. * Update 2019-08-28-21-40-12.bpo-37972.kP-n4L.rst added name of the contributor * bpo-37972: made all dunder methods chainable for _Call * bpo-37972: delegate only attributes of tuple instead to __getattr__ --- Lib/unittest/mock.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/unittest/mock.py') diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 50e4959655..a98decc2c9 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -2462,6 +2462,12 @@ class _Call(tuple): return _Call(name=name, parent=self, from_kall=False) + def __getattribute__(self, attr): + if attr in tuple.__dict__: + raise AttributeError + return tuple.__getattribute__(self, attr) + + def count(self, /, *args, **kwargs): return self.__getattr__('count')(*args, **kwargs) -- cgit v1.2.1