Title: Isinstance checks against Type[SomeProtocol] unexpectedly fails · Issue #7932 · python/mypy · GitHub
Open Graph Title: Isinstance checks against Type[SomeProtocol] unexpectedly fails · Issue #7932 · python/mypy
X Title: Isinstance checks against Type[SomeProtocol] unexpectedly fails · Issue #7932 · python/mypy
Description: Apologies in advance if this is a duplicate issue. When I try type-checking this program, the final line is inferred to be unreachable. This was a bit surprising to me: I expected to get a "Revealed type is 'SupportsLookup'" note instead...
Open Graph Description: Apologies in advance if this is a duplicate issue. When I try type-checking this program, the final line is inferred to be unreachable. This was a bit surprising to me: I expected to get a "Reveale...
X Description: Apologies in advance if this is a duplicate issue. When I try type-checking this program, the final line is inferred to be unreachable. This was a bit surprising to me: I expected to get a "Re...
Opengraph URL: https://github.com/python/mypy/issues/7932
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Isinstance checks against Type[SomeProtocol] unexpectedly fails","articleBody":"Apologies in advance if this is a duplicate issue.\r\n\r\nWhen I try type-checking this program, the final line is inferred to be unreachable. This was a bit surprising to me: I expected to get a \"Revealed type is 'SupportsLookup'\" note instead.\r\n\r\n```python\r\nfrom typing import Type\r\nfrom typing_extensions import Protocol\r\n\r\nclass SupportsLookup(Protocol):\r\n def lookup(self, key: str) -> int: ...\r\n\r\nclass Parent: pass\r\n\r\nclass Child(Parent):\r\n def lookup(self, key: str) -> int: ...\r\n\r\ndef cast_and_use(template: Type[SupportsLookup], x: Parent) -> None:\r\n if isinstance(x, template):\r\n reveal_type(x)\r\n```\r\n\r\nSomewhat curiously, if I make `x` be of type `object` instead of `Parent`, everything works as expected.\r\n\r\nThis seems a bit inconsistent to me. Assuming I'm not overlooking some type safety issue in my example, I think it'd be better to always narrow `x` to `SupportsLookup` regardless of how it's originally typed as long as the protocol doesn't directly conflict with any signatures defined in `Parent`.\r\n\r\nNote: this issue is a simplification of the root cause of the mypyc error I had in https://github.com/python/mypy/pull/7917 -- my original version of `make_indexing_replay_lookup_func` had this issue.","author":{"url":"https://github.com/Michael0x2a","@type":"Person","name":"Michael0x2a"},"datePublished":"2019-11-12T05:29:12Z","url":"https://github.com/python/mypy/issues/7932"}
| 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:0534e0ab-7628-eac5-5439-8b4c1a3b662c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEB4:100874:10C7810:16047FA:6B0007C4 |
| html-safe-nonce | 7540a9cf6eaf48f7163abb9759d31d44df9f526535b15987dab0e22174f61ec4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUI0OjEwMDg3NDoxMEM3ODEwOjE2MDQ3RkE6NkIwMDA3QzQiLCJ2aXNpdG9yX2lkIjoiNDQyMzM0MzE4MzA3NzgzNjc0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 70217e464a7412b85d82b63eba1fab30d77da83f0f2ef95d3248e76fe02c73cc |
| hovercard-subject-tag | issue:521337297 |
| 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/7932/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c5a15fe713a0bee56ab5e20a8e940aa94069d43802b9fd872ce6ca3b418878a/python/mypy/issues/7932 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c5a15fe713a0bee56ab5e20a8e940aa94069d43802b9fd872ce6ca3b418878a/python/mypy/issues/7932 |
| og:image:alt | Apologies in advance if this is a duplicate issue. When I try type-checking this program, the final line is inferred to be unreachable. This was a bit surprising to me: I expected to get a "Reveale... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Michael0x2a |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width