Title: Inconsistent Treatment of Class Constructor by Protocol · Issue #10482 · python/mypy · GitHub
Open Graph Title: Inconsistent Treatment of Class Constructor by Protocol · Issue #10482 · python/mypy
X Title: Inconsistent Treatment of Class Constructor by Protocol · Issue #10482 · python/mypy
Description: In the code below we define one protocol which, when called, returns another. In effect we're describing a "factory". However, while MyPy is able to recognize incorrect protocol implementations when given a function, it fails to do the s...
Open Graph Description: In the code below we define one protocol which, when called, returns another. In effect we're describing a "factory". However, while MyPy is able to recognize incorrect protocol implementations whe...
X Description: In the code below we define one protocol which, when called, returns another. In effect we're describing a "factory". However, while MyPy is able to recognize incorrect protocol imple...
Opengraph URL: https://github.com/python/mypy/issues/10482
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent Treatment of Class Constructor by Protocol","articleBody":"In the code below we define one protocol which, when called, returns another. In effect we're describing a \"factory\". However, while MyPy is able to recognize incorrect protocol implementations when given a function, it fails to do the same for class constructors.\r\n\r\nPlayground link: https://mypy-play.net/?mypy=latest&python=3.9&gist=3b9250b17032b659fc36746e659bcdb5\r\n\r\n```python\r\nfrom typing import Protocol\r\n\r\nclass Factory(Protocol):\r\n def __call__(self) -> Result:\r\n ...\r\n\r\nclass Result(Protocol):\r\n a: int\r\n \r\nclass BadImplementation:\r\n ...\r\n\r\ndef bad_implementation() -> BadImplementation:\r\n ...\r\n\r\nsomething: Factory = BadImplementation # no error\r\nsomething_else: Factory = bad_implementation # yes error\r\n```\r\n\r\nWe would expect MyPy to give an error in both cases given they result in the same type, but it only complains when given a standard function.","author":{"url":"https://github.com/rmorshea","@type":"Person","name":"rmorshea"},"datePublished":"2021-05-16T07:52:38Z","url":"https://github.com/python/mypy/issues/10482"}
| 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:d93f20c3-2041-44e7-3d11-36639776179e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B844:59CDA:300C8C5:3F3C772:6B002960 |
| html-safe-nonce | ec435039d69893d75de5320a5c249b4043e122881344a913780cff10d0fcb25b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODQ0OjU5Q0RBOjMwMEM4QzU6M0YzQzc3Mjo2QjAwMjk2MCIsInZpc2l0b3JfaWQiOiI0NzY1NTQ0NzMyNDUxNDE2NDE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fe013b476ec6012e3436e4ea5d16a16f7bad465587b856b4d4c469c03604d027 |
| hovercard-subject-tag | issue:892618709 |
| 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/10482/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f73b93abfc1ac1028f97071dc12aa4ff1871e7181ff318c2e3d877bf6dadbc2d/python/mypy/issues/10482 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f73b93abfc1ac1028f97071dc12aa4ff1871e7181ff318c2e3d877bf6dadbc2d/python/mypy/issues/10482 |
| og:image:alt | In the code below we define one protocol which, when called, returns another. In effect we're describing a "factory". However, while MyPy is able to recognize incorrect protocol implementations whe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rmorshea |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width