Title: Crash on generic class inside a function with a forward-reference bound · Issue #21550 · python/mypy · GitHub
Open Graph Title: Crash on generic class inside a function with a forward-reference bound · Issue #21550 · python/mypy
X Title: Crash on generic class inside a function with a forward-reference bound · Issue #21550 · python/mypy
Description: This crashes mypy: from typing import Generic, TypeVar def test() -> None: T = TypeVar("T", bound="Model") class Query(Generic[T]): def filter(self, value: T) -> None: raise NotImplementedError class Model: pass mypy (both 2.1.0 and curr...
Open Graph Description: This crashes mypy: from typing import Generic, TypeVar def test() -> None: T = TypeVar("T", bound="Model") class Query(Generic[T]): def filter(self, value: T) -> None: raise NotImplementedError cla...
X Description: This crashes mypy: from typing import Generic, TypeVar def test() -> None: T = TypeVar("T", bound="Model") class Query(Generic[T]): def filter(self, value: T) -> None: rai...
Opengraph URL: https://github.com/python/mypy/issues/21550
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash on generic class inside a function with a forward-reference bound","articleBody":"This crashes mypy:\n```python\nfrom typing import Generic, TypeVar\n\ndef test() -> None:\n T = TypeVar(\"T\", bound=\"Model\")\n\n class Query(Generic[T]):\n def filter(self, value: T) -> None:\n raise NotImplementedError\n\n class Model:\n pass\n```\n\nmypy (both 2.1.0 and current master) crashes on this with:\n\nAssertionError: Must not defer during final iteration\n\nNecessary pieces, from reduction:\n\n- The definitions need to be inside a function.\n- The TypeVar needs a forward-ref bound to a later local class: bound=\"Model\".\n- The local generic class needs to use that T in a method signature.\n\nSimilar issues: #12112, #13678, #18579.\n","author":{"url":"https://github.com/jelle-openai","@type":"Person","name":"jelle-openai"},"datePublished":"2026-05-27T23:25:45Z","url":"https://github.com/python/mypy/issues/21550"}
| 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:62ac4310-cfc8-6001-5d91-359361f20ea6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBD6:302FC:3D63AF:5253D5:6B002A0C |
| html-safe-nonce | 8ac827cd9d6a188641508eb1e49619bacbd0c6554cbce7f7aee75d9b932ab2a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkQ2OjMwMkZDOjNENjNBRjo1MjUzRDU6NkIwMDJBMEMiLCJ2aXNpdG9yX2lkIjoiODU1ODQxNDg5ODI1NjY4NTU4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 264f867cca85fcf4357b7d9973b9c4448b1a22c50aebdb14753d555e9dc25d03 |
| hovercard-subject-tag | issue:4536434963 |
| 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/21550/issue_layout |
| twitter:image | https://opengraph.githubassets.com/084012235090bba356913bf39458936c296490b01286165190fbe9823f44b0d1/python/mypy/issues/21550 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/084012235090bba356913bf39458936c296490b01286165190fbe9823f44b0d1/python/mypy/issues/21550 |
| og:image:alt | This crashes mypy: from typing import Generic, TypeVar def test() -> None: T = TypeVar("T", bound="Model") class Query(Generic[T]): def filter(self, value: T) -> None: raise NotImplementedError cla... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jelle-openai |
| 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