Title: Unsoundly accepts generic function with generic mutable default parameter · Issue #13054 · python/mypy · GitHub
Open Graph Title: Unsoundly accepts generic function with generic mutable default parameter · Issue #13054 · python/mypy
X Title: Unsoundly accepts generic function with generic mutable default parameter · Issue #13054 · python/mypy
Description: Mypy unsoundly accepts a generic function with a generic mutable default parameter value. This value is evaluated once at runtime, but can be referred to with multiple incompatible types, breaking type safety. from typing import TypeVar ...
Open Graph Description: Mypy unsoundly accepts a generic function with a generic mutable default parameter value. This value is evaluated once at runtime, but can be referred to with multiple incompatible types, breaking ...
X Description: Mypy unsoundly accepts a generic function with a generic mutable default parameter value. This value is evaluated once at runtime, but can be referred to with multiple incompatible types, breaking ...
Opengraph URL: https://github.com/python/mypy/issues/13054
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unsoundly accepts generic function with generic mutable default parameter","articleBody":"Mypy unsoundly accepts a generic function with a generic mutable default parameter value. This value is evaluated once at runtime, but can be referred to with multiple incompatible types, breaking type safety.\r\n\r\n```python\r\nfrom typing import TypeVar\r\n\r\nT = TypeVar(\"T\")\r\n\r\ndef f(x: T, y: list[T] = []) -> list[T]:\r\n return y\r\n\r\ny_strs: list[str] = f(\"a\")\r\ny_ints: list[int] = f(4)\r\n# Uh oh, y_strs and y_ints refer to the same list with incompatible types\r\ny_strs.append(\"b\")\r\nprint(y_ints[0] + 6) # oops\r\n```\r\n\r\n[mypy Playground link](https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&gist=3810190260a5a0436aa0d92fa0e0b9c8)\r\n\r\n(This is a sort of converse to #3737, where the complaint is that mypy _fails_ to accept a generic function with a _non-generic_ default parameter value. It further supports my [claim](https://github.com/python/mypy/issues/3737#issuecomment-552840010) that default parameter values should _not_ be generalized to the generic type of the parameter at function definition time.)\r\n\r\nRelated:\r\n- #11538\r\n- #11585\r\n- #3737\r\n","author":{"url":"https://github.com/andersk","@type":"Person","name":"andersk"},"datePublished":"2022-07-02T04:27:58Z","url":"https://github.com/python/mypy/issues/13054"}
| 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:874e9431-5a43-9c24-f8e5-0b26eeb0d1db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB4A:302FC:3E32D1:536779:6B002A48 |
| html-safe-nonce | d81ffc6aa223e32934ebc1fd3d46aa773e959e1bbb06da3de36c99ec74f81894 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjRBOjMwMkZDOjNFMzJEMTo1MzY3Nzk6NkIwMDJBNDgiLCJ2aXNpdG9yX2lkIjoiMTY0NTQ2OTAzNDUxMjEzMjY4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1feaa4dcdb048af92bb8846bba3e6dec786ad663fc9091c7f915035f1cef8507 |
| hovercard-subject-tag | issue:1291962384 |
| 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/13054/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac3ace870be22359c4b97fe4a0675351aefcfa8ded624bb5220ac369d9d1e94b/python/mypy/issues/13054 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac3ace870be22359c4b97fe4a0675351aefcfa8ded624bb5220ac369d9d1e94b/python/mypy/issues/13054 |
| og:image:alt | Mypy unsoundly accepts a generic function with a generic mutable default parameter value. This value is evaluated once at runtime, but can be referred to with multiple incompatible types, breaking ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andersk |
| 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