Title: bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable by blhsing · Pull Request #15565 · python/cpython · GitHub
Open Graph Title: bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable by blhsing · Pull Request #15565 · python/cpython
X Title: bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable by blhsing · Pull Request #15565 · python/cpython
Description: As reported on StackOverflow: https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call The following code: from unittest.mock import MagicMock, call mm = MagicMock() mm().foo()['bar'] print(mm.mock_calls) 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 an AttributeError 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
Open Graph Description: As reported on StackOverflow: https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call The following code: from unittest.mock import MagicMock, call mm = Magi...
X Description: As reported on StackOverflow: https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call The following code: from unittest.mock import MagicMock, call mm = Magi...
Opengraph URL: https://github.com/python/cpython/pull/15565
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6d006977-d466-cb70-1031-f6f7f1805f99 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B92C:24A400:7EE840:ADCE20:6A554C97 |
| html-safe-nonce | f2f209b79bd4d2f486b1ad10717db24dd18ece1b1082afebea91b0f3b969d95e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTJDOjI0QTQwMDo3RUU4NDA6QURDRTIwOjZBNTU0Qzk3IiwidmlzaXRvcl9pZCI6IjQ1MjI3NjM0OTQwNTYzNDg4MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4373f29a13d5cc1344bc0696d3a09537ceecbca3b3a5ab13b45024481e7a12ac |
| hovercard-subject-tag | pull_request:312039820 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/15565/files |
| twitter:image | https://avatars.githubusercontent.com/u/6724692?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/6724692?s=400&v=4 |
| og:image:alt | As reported on StackOverflow: https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call The following code: from unittest.mock import MagicMock, call mm = Magi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cd9eea424140838b22e9eabd53d92b5702617ddd6d76efcd3a37f08d44309ca5 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3084b9f587e8f1e19803bbe0c77ac77ce3c99c5c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width