Title: Defaulted TypeVar cannot be set to Never? · Issue #20391 · python/mypy · GitHub
Open Graph Title: Defaulted TypeVar cannot be set to Never? · Issue #20391 · python/mypy
X Title: Defaulted TypeVar cannot be set to Never? · Issue #20391 · python/mypy
Description: Bug Report I have a type variable with a default set. For some reason, this seems to be causing mypy to refuse to allow that variable to be Never in constructor calls, but it's not explicitly banned: it just seems to silently revert it t...
Open Graph Description: Bug Report I have a type variable with a default set. For some reason, this seems to be causing mypy to refuse to allow that variable to be Never in constructor calls, but it's not explicitly banne...
X Description: Bug Report I have a type variable with a default set. For some reason, this seems to be causing mypy to refuse to allow that variable to be Never in constructor calls, but it's not explicitly b...
Opengraph URL: https://github.com/python/mypy/issues/20391
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Defaulted TypeVar cannot be set to Never?","articleBody":"**Bug Report**\n\nI have a type variable with a default set. For some reason, this seems to be causing mypy to refuse to allow that variable to be `Never` in constructor calls, but it's not *explicitly* banned: it just seems to silently revert it to the default, causing weird errors.\n\n**To Reproduce**\n\n```python\nfrom typing import Generic, Never, TypeVar\n\nT = TypeVar(\"T\")\nD = TypeVar(\"D\", default=int)\n\nclass NoDefault(Generic[T]): pass\nclass WithDefault(Generic[D]): pass\n\nstr_no_default: NoDefault[str] = NoDefault()\nstr_with_default: WithDefault[str] = WithDefault()\nnever_no_default: NoDefault[Never] = NoDefault()\nnever_with_default: WithDefault[Never] = WithDefault()\n\nexplicit_with_default: WithDefault[Never] = WithDefault[Never]()\n```\n\n[Playground](https://mypy-play.net/?mypy=latest&python=3.12&gist=d60cb618cc559105c1c1b8387140b1c8)\n\n**Expected Behavior**\n\nI believe the above code should pass type-checking with no errors, as `Never` is a legal parameterization?\n\n**Actual Behavior**\n\n```text\nmain.py:12: error: Incompatible types in assignment (expression has type \"WithDefault[int]\", variable has type \"WithDefault[Never]\") [assignment]\nmain.py:14: error: Incompatible types in assignment (expression has type \"WithDefault[int]\", variable has type \"WithDefault[Never]\") [assignment]\nFound 2 errors in 1 file (checked 1 source file)\n```\n\nPlaying around, I can get all kinds of weird errors that seem to come down to mypy somehow reverting `Never` to the default bound in construction calls.\n\n**Your Environment**\n\n- Mypy version used: 1.19.0\n- Mypy command-line flags: None\n- Mypy configuration options from `mypy.ini` (and other config files): None\n- Python version used: 3.12\n\n","author":{"url":"https://github.com/alicederyn","@type":"Person","name":"alicederyn"},"datePublished":"2025-12-10T12:13:23Z","url":"https://github.com/python/mypy/issues/20391"}
| 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:e392104d-59a3-0014-bd6b-a40b1f975e79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A24C:308D9D:23E90C1:30F817B:6B0032C2 |
| html-safe-nonce | a55e6a0851f9632b40c7ba20c0324bc0e7203bc3ee682adb6a99c070af6eaa49 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjRDOjMwOEQ5RDoyM0U5MEMxOjMwRjgxN0I6NkIwMDMyQzIiLCJ2aXNpdG9yX2lkIjoiMjQ0MDM5NjAyNTYzMDgzMTI5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0a5232fcd3cffc7d90c930b1eb80872094917576bd16c47983e0c58a1c21d807 |
| hovercard-subject-tag | issue:3714946739 |
| 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/20391/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af4dd16d0de4e9e0bd5525142b54486ba06b0ca858ffcf4ca562b19d4276bdae/python/mypy/issues/20391 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af4dd16d0de4e9e0bd5525142b54486ba06b0ca858ffcf4ca562b19d4276bdae/python/mypy/issues/20391 |
| og:image:alt | Bug Report I have a type variable with a default set. For some reason, this seems to be causing mypy to refuse to allow that variable to be Never in constructor calls, but it's not explicitly banne... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alicederyn |
| 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