This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: does not chain __getitem__ to another _Call object
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: blhsing, cjw296, mariocj89, michael.foord, python-dev, xtreak
Priority: normal Keywords: patch

Created on 2019-08-28 20:33 by blhsing, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15565 merged blhsing, 2019-08-28 21:17
PR 15965 merged miss-islington, 2019-09-11 14:28
Messages (8)
msg350688 - (view) Author: Ben Hsing (blhsing) * Date: 2019-08-28 20:33
As reported on StackOverflow:

The following code would output: [call(), call().foo(), call().foo().__getitem__('bar')]

from unittest.mock import MagicMock, call
mm = MagicMock()

but trying to use that list with mm.assert_has_calls([call(), call().foo(), call().foo().__getitem__('bar')]) would result in:

TypeError: tuple indices must be integers or slices, not str
msg351830 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-09-11 11:34
If we go ahead with this then we should also support other dunder methods of tuple like __setitem__ and so on.
msg351846 - (view) Author: Ben Hsing (blhsing) * Date: 2019-09-11 12:45
Agreed. I've submitted a new commit with the call chaining behavior now generalized for all dunder methods by delegating the resolution of all attributes not directly in the _Call object's __dict__ keys to the getattr method.
msg351877 - (view) Author: Ben Hsing (blhsing) * Date: 2019-09-11 13:42
Correction. I've now done this by delegating the resolution of attributes belonging to the tuple class to _Call.__getattr__ instead. Passed all build tests.
msg351903 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2019-09-11 14:28
New changeset 72c359912d36705a94fca8b63d80451905a14ae4 by Michael Foord (blhsing) in branch 'master':
bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565)
msg352102 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2019-09-12 10:52
New changeset db0d8a5b2c803d30d9df436e00b6627ec8e09a13 by Michael Foord (Miss Islington (bot)) in branch '3.8':
bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565) (GH-15965)
msg354383 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-10-10 14:40
Closing as fixed since PRs were merged. Thanks Ben.
msg360973 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2020-01-29 16:25
New changeset db5e86adbce12350c26e7ffc2c6673369971a2dc by Chris Withers in branch 'master':
Get mock coverage back to 100% (GH-18228)
Date User Action Args
2022-04-11 14:59:19adminsetgithub: 82153
2020-01-29 16:25:00cjw296setmessages: + msg360973
2019-10-10 14:40:24xtreaksetstatus: open -> closed
resolution: fixed
messages: + msg354383

stage: patch review -> resolved
2019-09-12 10:52:52python-devsetmessages: + msg352102
2019-09-11 14:28:20miss-islingtonsetpull_requests: + pull_request15598
2019-09-11 14:28:09python-devsetnosy: + python-dev
messages: + msg351903
2019-09-11 13:42:18blhsingsetmessages: + msg351877
2019-09-11 12:59:00blhsingsetstatus: pending -> open
2019-09-11 12:45:03blhsingsetstatus: open -> pending

messages: + msg351846
2019-09-11 11:34:48xtreaksetnosy: + cjw296, michael.foord, mariocj89

messages: + msg351830
versions: - Python 2.7, Python 3.5, Python 3.6, Python 3.7
2019-08-28 21:17:21blhsingsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15240
2019-08-28 20:58:09xtreaksetnosy: + xtreak
2019-08-28 20:33:01blhsingcreate