Title: Mypy throws errors when MagicMock-ing a method · Issue #6713 · python/mypy · GitHub
Open Graph Title: Mypy throws errors when MagicMock-ing a method · Issue #6713 · python/mypy
X Title: Mypy throws errors when MagicMock-ing a method · Issue #6713 · python/mypy
Description: Using Python 3.7 and MyPy 0.700. When MagicMocking a method and then using MagicMock methods, mypy complains that the mocked method does not have the attribute "assert_called" and other MagicMock methods. I'm not sure if it's at all poss...
Open Graph Description: Using Python 3.7 and MyPy 0.700. When MagicMocking a method and then using MagicMock methods, mypy complains that the mocked method does not have the attribute "assert_called" and other MagicMock m...
X Description: Using Python 3.7 and MyPy 0.700. When MagicMocking a method and then using MagicMock methods, mypy complains that the mocked method does not have the attribute "assert_called" and other M...
Opengraph URL: https://github.com/python/mypy/issues/6713
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypy throws errors when MagicMock-ing a method","articleBody":"Using Python 3.7 and MyPy 0.700.\r\n\r\nWhen MagicMocking a method and then using MagicMock methods, mypy complains that the mocked method does not have the attribute \"assert_called\" and other MagicMock methods.\r\nI'm not sure if it's at all possible for mypy to understand a method was monkey-patched like this, but it makes checking tests involving Mocks with mypy is not practical. Ideally, this code should not throw any errors.\r\n\r\nFor example:\r\n```\r\nfrom unittest.mock import MagicMock\r\n\r\n\r\nclass Foo:\r\n def bar(self) -> None:\r\n pass\r\n\r\n\r\nfoo = Foo()\r\nfoo.bar = MagicMock()\r\nfoo.bar()\r\nfoo.bar.assert_called()\r\n```\r\n\r\nWhen running Mypy, you get:\r\n\r\n```\r\ntest.py:10: error: Cannot assign to a method\r\ntest.py:12: error: \"Callable[[], None]\" has no attribute \"assert_called\"\r\n```\r\n\r\nThe first error is already discussed in https://github.com/python/mypy/issues/2427.\r\nI couldn't find an issue discussing the second error.","author":{"url":"https://github.com/MatanRubin","@type":"Person","name":"MatanRubin"},"datePublished":"2019-04-23T09:45:51Z","url":"https://github.com/python/mypy/issues/6713"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b2988403-5187-30da-c704-ca4ae5c7d643 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96B2:14B836:C35235:104FDBD:6B004E8B |
| html-safe-nonce | 3b94dcb561f7793ed1b10d0a9104210c9c26e402012c90f3536749f5e90e4656 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkIyOjE0QjgzNjpDMzUyMzU6MTA0RkRCRDo2QjAwNEU4QiIsInZpc2l0b3JfaWQiOiI0MzczNjU5ODc2NTQ3ODI2MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4a9ea164482f23020556f4166eac7a8b45fe344cb2afa8102e70c51352d3f22b |
| hovercard-subject-tag | issue:436095788 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/mypy/6713/issue_layout |
| twitter:image | https://opengraph.githubassets.com/86c37a48bce73710deeb9929cd0f12dd33f44191dcf09a3174e430a2cf91d472/python/mypy/issues/6713 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/86c37a48bce73710deeb9929cd0f12dd33f44191dcf09a3174e430a2cf91d472/python/mypy/issues/6713 |
| og:image:alt | Using Python 3.7 and MyPy 0.700. When MagicMocking a method and then using MagicMock methods, mypy complains that the mocked method does not have the attribute "assert_called" and other MagicMock m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MatanRubin |
| hostname | github.com |
| expected-hostname | github.com |
| None | f9517bf360d46638a1e5e7daee7158842fe5ef43c9000afa0e127564a7c2f39b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b27c5dde30676028abd5c5fc53ce5c9b625f8281 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width