Title: `issubclass()` doesn't narrow down types of type variables · Issue #7920 · python/mypy · GitHub
Open Graph Title: `issubclass()` doesn't narrow down types of type variables · Issue #7920 · python/mypy
X Title: `issubclass()` doesn't narrow down types of type variables · Issue #7920 · python/mypy
Description: Example: from typing import * TypeT = TypeVar("TypeT", bound=type) class Base: field: str = "Hey" class C1: def method(self, other: type) -> str: if issubclass(other, Base): # reveal_type(other) == Type[Base] return other.field return "H...
Open Graph Description: Example: from typing import * TypeT = TypeVar("TypeT", bound=type) class Base: field: str = "Hey" class C1: def method(self, other: type) -> str: if issubclass(other, Base): # reveal_type(other) ==...
X Description: Example: from typing import * TypeT = TypeVar("TypeT", bound=type) class Base: field: str = "Hey" class C1: def method(self, other: type) -> str: if issubclass(other, Base): ...
Opengraph URL: https://github.com/python/mypy/issues/7920
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`issubclass()` doesn't narrow down types of type variables","articleBody":"Example:\r\n```py3\r\nfrom typing import *\r\n\r\nTypeT = TypeVar(\"TypeT\", bound=type)\r\n\r\nclass Base:\r\n field: str = \"Hey\"\r\n\r\nclass C1:\r\n def method(self, other: type) -> str:\r\n if issubclass(other, Base):\r\n # reveal_type(other) == Type[Base]\r\n return other.field\r\n return \"Hi\"\r\n\r\nclass C2(Generic[TypeT]):\r\n def method(self, other: TypeT) -> str:\r\n if issubclass(other, Base):\r\n # reveal_type(other) == TypeT`1\r\n return other.field # mypy error: \"TypeT\" has no attribute \"field\"\r\n return \"Hi\"\r\n```\r\n\r\nActual behavior as of 0.740 included in the comments above. Expected behavior would be to not raise an error on the penultimate line.","author":{"url":"https://github.com/ambv","@type":"Person","name":"ambv"},"datePublished":"2019-11-11T14:27:09Z","url":"https://github.com/python/mypy/issues/7920"}
| 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:8f7ec0ff-2a13-806c-82c5-5fdad947bd19 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D47C:2ED6B1:798EE:AA4C5:6B005131 |
| html-safe-nonce | 9b2fe0f56e4ee2e7f9633c07c7a6cf45bc582710fb31171c8f3d8744dc278279 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDdDOjJFRDZCMTo3OThFRTpBQTRDNTo2QjAwNTEzMSIsInZpc2l0b3JfaWQiOiI0NTA2MzczNDg2NTQ5MTYwMjQxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e26ee9f5b3e2261cc64aa4e09681686b1460c28fc0a35d794d1337027ce5dcb8 |
| hovercard-subject-tag | issue:520994131 |
| 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/7920/issue_layout |
| twitter:image | https://opengraph.githubassets.com/34019c1c9c0ddf531dd26a9d4f5c7cfd40a59d18c778276968b0975ea2b9dd32/python/mypy/issues/7920 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/34019c1c9c0ddf531dd26a9d4f5c7cfd40a59d18c778276968b0975ea2b9dd32/python/mypy/issues/7920 |
| og:image:alt | Example: from typing import * TypeT = TypeVar("TypeT", bound=type) class Base: field: str = "Hey" class C1: def method(self, other: type) -> str: if issubclass(other, Base): # reveal_type(other) ==... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ambv |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width