Title: [regression] isinstance complains about parametrized generics with any use of TypeAlias · Issue #18488 · python/mypy · GitHub
Open Graph Title: [regression] isinstance complains about parametrized generics with any use of TypeAlias · Issue #18488 · python/mypy
X Title: [regression] isinstance complains about parametrized generics with any use of TypeAlias · Issue #18488 · python/mypy
Description: Bug Report Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, even if the aliased type is non-generic. ...
Open Graph Description: Bug Report Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, e...
X Description: Bug Report Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, e...
Opengraph URL: https://github.com/python/mypy/issues/18488
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[regression] isinstance complains about parametrized generics with any use of TypeAlias","articleBody":"**Bug Report**\n\nAny attempt to call `isinstance` with a variable annotated as a `TypeAlias` seems to result in the error message `error: Parameterized generics cannot be used with class or instance checks`, even if the aliased type is non-generic. mypy_primer points at https://github.com/python/mypy/pull/18173 as the breaking commit, but that PR seems to have been intended to deal with type aliases of generic types; it seems that we're treating _all_ `TypeAlias`-based aliases as generic types, which AFAICT is broader than intended. \n\n**To Reproduce**\n\n[MyPy playground link](https://mypy-play.net/?mypy=master&python=3.12&gist=dedafca242fde5949bad614b4668806f), using current master\n\n```python\nfrom typing import Any, TypeAlias\n\nclass Foo:\n pass\n\nAlias: TypeAlias = Foo\n\ndef is_foo(x: Any) -> bool:\n return isinstance(x, Alias)\n```\n\n**Expected Behavior**\n\nMyPy finds no errors, matching the runtime behavior. Pyright and mypy 1.4 both find no errors in my minimal example.\n\n**Actual Behavior**\n\nPer the playground link:\n\n```\nmain.py:9: error: Parameterized generics cannot be used with class or instance checks [misc]\nFound 1 error in 1 file (checked 1 source file)\n```\n\n**Your Environment**\n\nI found this when dogfooding mypy master commit c4e2eb79905d7b381db8caed161cebb04622ebc2 against Dropbox's internal Python repo, but mypy_primer also reproduces the same thing, as does mypy playground. ","author":{"url":"https://github.com/wesleywright","@type":"Person","name":"wesleywright"},"datePublished":"2025-01-19T17:49:37Z","url":"https://github.com/python/mypy/issues/18488"}
| 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:d36590d2-9c1e-f6f1-9694-c8c0c9ab7b0f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D87E:1EFC1C:F58011:140D8A5:6AFFF558 |
| html-safe-nonce | 6a6b903eca2308a7e664c40d92e8b6a47969a9235bdb6c9698ada99ce5414f8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODdFOjFFRkMxQzpGNTgwMTE6MTQwRDhBNTo2QUZGRjU1OCIsInZpc2l0b3JfaWQiOiIzNTAxODI0MjkwMDYyMzMzMjcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bb566942e2b9e1680dfc91a68d65e0f9e245372e25943c80e2f65faab779c57d |
| hovercard-subject-tag | issue:2797748691 |
| 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/18488/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1c9fc5a4b22c4830a1fd1328b65de982ab1aea25c7eea5aa0b02af8762fd4223/python/mypy/issues/18488 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1c9fc5a4b22c4830a1fd1328b65de982ab1aea25c7eea5aa0b02af8762fd4223/python/mypy/issues/18488 |
| og:image:alt | Bug Report Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wesleywright |
| 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