Title: Segfault on class parameterised by a TypeVar whose default is itself (TypeVar("T", default="T")) · Issue #22344 · python/mypy · GitHub
Open Graph Title: Segfault on class parameterised by a TypeVar whose default is itself (TypeVar("T", default="T")) · Issue #22344 · python/mypy
X Title: Segfault on class parameterised by a TypeVar whose default is itself (TypeVar("T", default="T")) · Issue #22344 · python/mypy
Description: Crash Report Compiled mypy segfaults on a class parameterised by TypeVar("T", default="T"). Uncompiled mypy raises RecursionError. T = TypeVar("T", default="T") on its own and def f(x: T) -> T do not crash. It also crashes with typing_ex...
Open Graph Description: Crash Report Compiled mypy segfaults on a class parameterised by TypeVar("T", default="T"). Uncompiled mypy raises RecursionError. T = TypeVar("T", default="T") on its own and def f(x: T) -> T do n...
X Description: Crash Report Compiled mypy segfaults on a class parameterised by TypeVar("T", default="T"). Uncompiled mypy raises RecursionError. T = TypeVar("T", default="T&quo...
Opengraph URL: https://github.com/python/mypy/issues/22344
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault on class parameterised by a TypeVar whose default is itself (TypeVar(\"T\", default=\"T\"))","articleBody":"**Crash Report**\n\nCompiled mypy segfaults on a class parameterised by `TypeVar(\"T\", default=\"T\")`. Uncompiled mypy raises `RecursionError`. `T = TypeVar(\"T\", default=\"T\")` on its own and `def f(x: T) -> T` do not crash. It also crashes with `typing_extensions.TypeVar` and with `--python-version 3.12`.\n\nRelated but different: #16940 (`bound=Callable[..., \"T\"]`), whose fix in #22341 does not fix this case. Recursive defaults involving aliases or other type variables were fixed in #21491, but this self-reference still crashes on current master.\n\n**Traceback**\n\nUncompiled mypy 2.5.0+dev.6972572 (master with the fix from #22341 applied), `--show-traceback`. Compiled mypy only prints `Segmentation fault`.\n\n```python-traceback\nerror: INTERNAL ERROR -- Please try using mypy master on GitHub:\n ... mypy/semanal.py in visit_class_def\n ... mypy/semanal_shared.py in has_placeholder\n ... mypy/type_visitor.py in visit_instance\n ... mypy/type_visitor.py in query_types\n ... mypy/types.py in accept\n ... mypy/type_visitor.py in visit_type_var\n ... mypy/type_visitor.py in query_types\n ... (visit_type_var -> query_types -> accept repeats until the limit)\nRecursionError: maximum recursion depth exceeded\n```\n\n**To Reproduce**\n\nPlayground: https://mypy-play.net/?gist=476ed39bd34e3b39b4d3c155c4a2f82b\n\n```python\nfrom typing import Generic, TypeVar\n\nT = TypeVar(\"T\", default=\"T\")\n\nclass C(Generic[T]): ...\n```\n\n```\nmypy case.py\n```\n\n**Expected Behavior**\n\nAn error about an invalid or self-referential default, such as `Cannot resolve name \"T\" (possible cyclic definition)`. That is what mypy reports for `TypeVar(\"T\", bound=list[\"T\"])`.\n\n**Actual Behavior**\n\n`Segmentation fault (core dumped)` (exit 139) with compiled mypy 2.4.0 and 2.4.1. Playground: \u003cwhat it shows, e.g. \"Failed (exit code: -11)\">.\n\n**Your Environment**\n\n- Mypy version used: mypy latest (2.4.1) in the playground; 2.4.1 and 2.4.0 (compiled) segfault locally; 2.5.0+dev.6972572 (uncompiled) raises RecursionError\n- Mypy command-line flags: `--python-version 3.13` (also crashes with 3.12)\n- Mypy configuration options from `mypy.ini` (and other config files): none\n- Python version used: \u003c3.12 in the playground / your local version>\n- Operating system and version: \u003cyour OS>\n","author":{"url":"https://github.com/Choco-princess","@type":"Person","name":"Choco-princess"},"datePublished":"2026-11-01T16:36:16Z","url":"https://github.com/python/mypy/issues/22344"}
| 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:6adb7c3b-3911-9b2f-598c-13f8aa51fbb3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6AA:C5FC2:184FBD5:20149BA:6B00258B |
| html-safe-nonce | 1c9c679d4a86eacf7f131d5c790d909a6623a300f7c3e79b2891aa86ac84508b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkFBOkM1RkMyOjE4NEZCRDU6MjAxNDlCQTo2QjAwMjU4QiIsInZpc2l0b3JfaWQiOiI0MzA4NDQ3MDYxMjQzNjAyMzE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 726aedc0207008fc05dd7ed2941e4705cd935a336f23c12a2ed2c81fb8572787 |
| hovercard-subject-tag | issue:6149353330 |
| 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/22344/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8a5e48af0b131afd4a48fe03647840ee5b0d95c7ef78598109f329042acfdd74/python/mypy/issues/22344 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8a5e48af0b131afd4a48fe03647840ee5b0d95c7ef78598109f329042acfdd74/python/mypy/issues/22344 |
| og:image:alt | Crash Report Compiled mypy segfaults on a class parameterised by TypeVar("T", default="T"). Uncompiled mypy raises RecursionError. T = TypeVar("T", default="T") on its own and def f(x: T) -> T do n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Choco-princess |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width