Title: Arguments annotated with typevars cannot have defaults · Issue #19092 · python/mypy · GitHub
Open Graph Title: Arguments annotated with typevars cannot have defaults · Issue #19092 · python/mypy
X Title: Arguments annotated with typevars cannot have defaults · Issue #19092 · python/mypy
Description: Bug Report Adding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked out of the box. To Reproduce https://mypy-...
Open Graph Description: Bug Report Adding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked ou...
X Description: Bug Report Adding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked ou...
Opengraph URL: https://github.com/python/mypy/issues/19092
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Arguments annotated with typevars cannot have defaults","articleBody":"**Bug Report**\n\nAdding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked out of the box.\n\n**To Reproduce**\n\nhttps://mypy-play.net/?mypy=latest&python=3.12&gist=d0bdf572dbd887f02855ac9c4a28f20f\n```python\nfrom typing import TypeVar\n\nclass Base:\n pass\n\nT = TypeVar('T')\n# Also fails: T = TypeVar('T', bound=Base)\n\ndef foo1(obj: T = Base()) -> list[T]:\n return [obj]\n\ndef foo2(ty: type[T] = Base) -> list[T]:\n return [ty()]\n```\n\n**Expected Behavior**\n\nThis should type-check with no errors.\n\n**Actual Behavior**\n\n```\nmain.py:9: error: Incompatible default for argument \"obj\" (default has type \"Base\", argument has type \"T\") [assignment]\nmain.py:12: error: Incompatible default for argument \"ty\" (default has type \"type[Base]\", argument has type \"type[T]\") [assignment]\n```\n\n**Your Environment**\n\n- Mypy version used: 1.15.0\n- Python version used: 3.11\n","author":{"url":"https://github.com/eltoder","@type":"Person","name":"eltoder"},"datePublished":"2025-05-15T19:11:34Z","url":"https://github.com/python/mypy/issues/19092"}
| 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:5d7cecf5-0796-c6ba-31fb-044de0d516cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9704:392206:FB9470:149B8C6:6AFFF930 |
| html-safe-nonce | 66e70c8b3b157b08945a65838d61c09bea661290e9c85339b325051481883db4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzA0OjM5MjIwNjpGQjk0NzA6MTQ5QjhDNjo2QUZGRjkzMCIsInZpc2l0b3JfaWQiOiI4MDUzNDA3NDYzODYyNDM0MDk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 326bebfb8a4add3ed2a173276168d6d126e834262f73591c50ca710941002744 |
| hovercard-subject-tag | issue:3067167277 |
| 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/19092/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0b9e487f0f1af159227719eedaee5ae73111f7b0fd56afb838f38c2f4bb39f35/python/mypy/issues/19092 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0b9e487f0f1af159227719eedaee5ae73111f7b0fd56afb838f38c2f4bb39f35/python/mypy/issues/19092 |
| og:image:alt | Bug Report Adding a default value for a function argument that uses a TypeVar in its type results in an error. This can be worked-around using overloads, but it would be better if it just worked ou... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eltoder |
| 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