Title: Incorrect handling of default arguments for type Type with Typevars · Issue #6525 · python/mypy · GitHub
Open Graph Title: Incorrect handling of default arguments for type Type with Typevars · Issue #6525 · python/mypy
X Title: Incorrect handling of default arguments for type Type with Typevars · Issue #6525 · python/mypy
Description: Consider a function which takes type and returns instance of that type. This is handled correctly by mypy: from typing import Type, TypeVar MyType = TypeVar('MyType', str, int) def func(t: Type[MyType]) -> MyType: return t() However, if ...
Open Graph Description: Consider a function which takes type and returns instance of that type. This is handled correctly by mypy: from typing import Type, TypeVar MyType = TypeVar('MyType', str, int) def func(t: Type[MyT...
X Description: Consider a function which takes type and returns instance of that type. This is handled correctly by mypy: from typing import Type, TypeVar MyType = TypeVar('MyType', str, int) def func(t: ...
Opengraph URL: https://github.com/python/mypy/issues/6525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect handling of default arguments for type Type with Typevars","articleBody":"Consider a function which takes type and returns instance of that type. This is handled correctly by mypy:\r\n\r\n```python\r\nfrom typing import Type, TypeVar\r\n\r\nMyType = TypeVar('MyType', str, int)\r\n\r\ndef func(t: Type[MyType]) -> MyType:\r\n return t()\r\n```\r\n\r\nHowever, if I set default argument for t, mypy fails:\r\n\r\n```python\r\nfrom typing import Type, TypeVar\r\n\r\nMyType = TypeVar('MyType', str, int)\r\n\r\n# error: Incompatible default for argument \"t\" (default has type \"Type[str]\", argument has type \"Type[int]\")\r\ndef func(t: Type[MyType] = str) -> MyType:\r\n return t()\r\n```\r\n```python\r\nfrom typing import Type, TypeVar\r\n\r\nMyType = TypeVar('MyType', str, int)\r\n\r\n# error: Incompatible default for argument \"t\" (default has type \"Type[int]\", argument has type \"Type[str]\")\r\ndef func(t: Type[MyType] = int) -> MyType:\r\n return t()\r\n```\r\n```python\r\nfrom typing import Type, TypeVar\r\n\r\nMyType = TypeVar('MyType')\r\n\r\n# error: Incompatible default for argument \"t\" (default has type \"Type[int]\", argument has type \"Type[MyType]\")\r\ndef func(t: Type[MyType] = int) -> MyType:\r\n return t()\r\n```\r\n\r\nIMO that's a bug. Without TypeVar it works correctly though:\r\n\r\n```python\r\nfrom typing import Type, TypeVar, Union\r\n\r\ndef func(t: Type[Union[str, int]] = str) -> Union[str, int]:\r\n return t()\r\n```","author":{"url":"https://github.com/AMDmi3","@type":"Person","name":"AMDmi3"},"datePublished":"2019-03-08T00:30:12Z","url":"https://github.com/python/mypy/issues/6525"}
| 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:6eab1686-b118-9a24-99ad-e0e2cd5a1bce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACBC:2A4B31:4C23CA:66A884:6B002FEF |
| html-safe-nonce | 41c11fa6c2cb99b07d6aba17fe9500ce08a718e0f07f51aa79484f931cbd15b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0JDOjJBNEIzMTo0QzIzQ0E6NjZBODg0OjZCMDAyRkVGIiwidmlzaXRvcl9pZCI6IjI4MjkwNzU5MzI5NjUyNTMxMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4163052b023dc3a500cdfb7b1886f3a1bcfb7eb5d36e4b2bc0cafa7bee23e71b |
| hovercard-subject-tag | issue:418577761 |
| 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/6525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da99fbd978c340c3e8a5f92bcc150ea6d0fa1772120156b2ff0bf1809b479db6/python/mypy/issues/6525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da99fbd978c340c3e8a5f92bcc150ea6d0fa1772120156b2ff0bf1809b479db6/python/mypy/issues/6525 |
| og:image:alt | Consider a function which takes type and returns instance of that type. This is handled correctly by mypy: from typing import Type, TypeVar MyType = TypeVar('MyType', str, int) def func(t: Type[MyT... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AMDmi3 |
| 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