Title: Fallback overloads for literal argument · Issue #5493 · python/typeshed · GitHub
Open Graph Title: Fallback overloads for literal argument · Issue #5493 · python/typeshed
X Title: Fallback overloads for literal argument · Issue #5493 · python/typeshed
Description: Currently, we use an extra str overload when using literals. For example: @overload def open(mode: Literal["r"] = ...) -> int: ... @overload def open(mode: Literal["w"]) -> str: ... @overload def open(mode: str) -> str | int: ... What's ...
Open Graph Description: Currently, we use an extra str overload when using literals. For example: @overload def open(mode: Literal["r"] = ...) -> int: ... @overload def open(mode: Literal["w"]) -> str: ... @overload def o...
X Description: Currently, we use an extra str overload when using literals. For example: @overload def open(mode: Literal["r"] = ...) -> int: ... @overload def open(mode: Literal["w"]) ->...
Opengraph URL: https://github.com/python/typeshed/issues/5493
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fallback overloads for literal argument","articleBody":"Currently, we use an extra `str` overload when using literals. For example:\r\n\r\n```python\r\n@overload\r\ndef open(mode: Literal[\"r\"] = ...) -> int: ...\r\n@overload\r\ndef open(mode: Literal[\"w\"]) -> str: ...\r\n@overload\r\ndef open(mode: str) -> str | int: ...\r\n```\r\nWhat's the use case for this? The only thing I can think of is something like this:\r\n\r\n```python\r\nmode: str = ...\r\nopen(mode)\r\n```\r\n\r\nBut this actually looks like a typing error to me where `mode` should have been annotated with `Literal[\"r\", \"w\"]` anyway. I would suggest starting to remove these defaults, possibly after the next mypy version is released. primer should warn us if this causes lots of new errors (as I would expect for e.g `builtins.open()`) and we can then decide on a case-by-case basis to leave the default in for now.\r\n\r\nSide note: We can't do this for `bool` yet due to python/mypy#6113.","author":{"url":"https://github.com/srittau","@type":"Person","name":"srittau"},"datePublished":"2021-05-18T08:01:35Z","url":"https://github.com/python/typeshed/issues/5493"}
| 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:a167e016-289d-2227-63f3-0e98efb4bcfc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E4C:137B3:17F4B33:1F95FF9:6B0024C3 |
| html-safe-nonce | f53d41325dd2b95458c45ccbe1169ac850c9f8d029befd7e26b9a33d2771898c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTRDOjEzN0IzOjE3RjRCMzM6MUY5NUZGOTo2QjAwMjRDMyIsInZpc2l0b3JfaWQiOiI1NDEyODM2NDc0Nzg3NzM0NzIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ef9c454df80481ed512bb25aca6a37fba8551058e2a28af2708ebb10c465eefe |
| hovercard-subject-tag | issue:894095774 |
| 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/typeshed/5493/issue_layout |
| twitter:image | https://opengraph.githubassets.com/daa6296f75ebc334120cb674ef48dd49b23ecf1f4a01e22731fb89861d7dc9b4/python/typeshed/issues/5493 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/daa6296f75ebc334120cb674ef48dd49b23ecf1f4a01e22731fb89861d7dc9b4/python/typeshed/issues/5493 |
| og:image:alt | Currently, we use an extra str overload when using literals. For example: @overload def open(mode: Literal["r"] = ...) -> int: ... @overload def open(mode: Literal["w"]) -> str: ... @overload def o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | srittau |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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