Title: Type guard doesn't intersect types like instance check · Issue #1351 · python/typing · GitHub
Open Graph Title: Type guard doesn't intersect types like instance check · Issue #1351 · python/typing
X Title: Type guard doesn't intersect types like instance check · Issue #1351 · python/typing
Description: The type guard doesn't seem to work like an instance check: from typing import TypeGuard, Any class X: pass class Y: pass x: X = X() assert isinstance(x, Y) def f(z: Any) -> TypeGuard[Y]: return isinstance(z, Y) reveal_type(x) # Revealed...
Open Graph Description: The type guard doesn't seem to work like an instance check: from typing import TypeGuard, Any class X: pass class Y: pass x: X = X() assert isinstance(x, Y) def f(z: Any) -> TypeGuard[Y]: return is...
X Description: The type guard doesn't seem to work like an instance check: from typing import TypeGuard, Any class X: pass class Y: pass x: X = X() assert isinstance(x, Y) def f(z: Any) -> TypeGuard[Y]: re...
Opengraph URL: https://github.com/python/typing/issues/1351
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type guard doesn't intersect types like instance check","articleBody":"The type guard doesn't seem to work like an instance check:\r\n```python\r\nfrom typing import TypeGuard, Any\r\nclass X: pass\r\nclass Y: pass\r\nx: X = X()\r\nassert isinstance(x, Y)\r\ndef f(z: Any) -> TypeGuard[Y]:\r\n return isinstance(z, Y)\r\nreveal_type(x) # Revealed type is \"a.\u003csubclass of \"X\" and \"Y\">\", which is great!\r\nx2: X\r\nassert f(x2)\r\nreveal_type(x2) # Revealed type is \"a.Y\", which is unfortunate.\r\n```\r\nThis is causing problems with the definition of `dataclasses.is_dataclass` https://github.com/python/typeshed/issues/9723.\r\n\r\nThe above code was tested with MyPy and Pyright.","author":{"url":"https://github.com/NeilGirdhar","@type":"Person","name":"NeilGirdhar"},"datePublished":"2023-02-18T18:18:48Z","url":"https://github.com/python/typing/issues/1351"}
| 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:295a59b6-9e7d-e5d2-d9d5-6c913c83f34b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0A4:326AD2:293D78:395955:6B008910 |
| html-safe-nonce | 1bf7b05f1a887e12ca2d82724d2c9aea9757c604d13e503c5cad97edbb29319d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEE0OjMyNkFEMjoyOTNENzg6Mzk1OTU1OjZCMDA4OTEwIiwidmlzaXRvcl9pZCI6Ijg5MDEwODQ0OTE2OTEzNjI1NzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5c62f2c05700e0ea04b126d4a67236b5252119998b12a9b368f180db81226b31 |
| hovercard-subject-tag | issue:1590427495 |
| 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/typing/1351/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1db1dda68603019cff254f1d7cde2c3bfc9ddace9c4692181c3f30505870ddd0/python/typing/issues/1351 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1db1dda68603019cff254f1d7cde2c3bfc9ddace9c4692181c3f30505870ddd0/python/typing/issues/1351 |
| og:image:alt | The type guard doesn't seem to work like an instance check: from typing import TypeGuard, Any class X: pass class Y: pass x: X = X() assert isinstance(x, Y) def f(z: Any) -> TypeGuard[Y]: return is... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | NeilGirdhar |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width