-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable #15565
Conversation
…attr__ chaining so that call() can be subscriptable
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
added name of the contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nice catch and fix.
Thanks @blhsing for the PR, and @voidspace for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
…attr__ chaining so that call() can be subscriptable (pythonGH-15565) * 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__ (cherry picked from commit 72c3599) Co-authored-by: blhsing <github@ydooby.com>
GH-15965 is a backport of this pull request to the 3.8 branch. |
…attr__ chaining so that call() can be subscriptable (GH-15565) (GH-15965) * 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__ (cherry picked from commit 72c3599) Co-authored-by: blhsing <github@ydooby.com>
…attr__ chaining so that call() can be subscriptable (pythonGH-15565) * 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__
As reported on StackOverflow:
https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call
The following code:
would output:
[call(), call().foo(), call().foo().__getitem__('bar')]
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
This fix now makes
unittest.mock._Call.__getattribute__
raise anAttributeError
when the given attribute name is'__getitem__'
so that__getitem__
can get the same chaining mechanism provided by the__getattr__
method.https://bugs.python.org/issue37972