Title: Introduce an Unknown type · Issue #1835 · python/typing · GitHub
Open Graph Title: Introduce an Unknown type · Issue #1835 · python/typing
X Title: Introduce an Unknown type · Issue #1835 · python/typing
Description: Unknown Definition A type that can only be cast to Any Problem Currently when type checkers fail to understand the type of a function/variable, they fallback on Any. T = TypeVar("T") def foo(fn: Callable[[], T]) -> T: return fn() bar = f...
Open Graph Description: Unknown Definition A type that can only be cast to Any Problem Currently when type checkers fail to understand the type of a function/variable, they fallback on Any. T = TypeVar("T") def foo(fn: Ca...
X Description: Unknown Definition A type that can only be cast to Any Problem Currently when type checkers fail to understand the type of a function/variable, they fallback on Any. T = TypeVar("T") def ...
Opengraph URL: https://github.com/python/typing/issues/1835
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Introduce an Unknown type","articleBody":"\u003c!-- Please describe the problem you face as well as your idea below, ideally using examples for both. -->\n\n## `Unknown` Definition\nA type that can only be cast to `Any`\n\n## Problem\n\nCurrently when type checkers fail to understand the type of a function/variable, they fallback on `Any`.\n\n```python\nT = TypeVar(\"T\")\n\ndef foo(fn: Callable[[], T]) -> T:\n return fn()\n\nbar = foo(lambda: 5)\n\n# The type of bar will fallback on `Any` so the type checker will not warn on misuse\n_ = bar[0]\n```\n\n## Suggestion\n\nIf an `Unknown` type is introduced, and can be defined as a fallback in the checker then all operations performed on it (that assume a specific type) will fail.\n\n```python\nT = TypeVar(\"T\")\n\ndef foo(fn: Callable[[], T]) -> T:\n return fn()\n\nbar = foo(lambda: 5)\n\n# The checker will mark this as an error because subscripting is not defined on \n`Unknown`.\n_ = bar[0]\n```\n\n## Inspirations\n\nTypescript: https://www.typescriptlang.org/docs/handbook/type-compatibility.html#any-unknown-object-void-undefined-null-and-never-assignability\n\n> `any` and `unknown` are the same in terms of what is assignable to them, different in that `unknown` is not assignable to anything except `any`.\n> \n> `unknown` and `never` are like inverses of each other. Everything is assignable to `unknown`, `never` is assignable to everything. Nothing is assignable to `never`, `unknown` is not assignable to anything (except `any`).","author":{"url":"https://github.com/Eyal-Shalev","@type":"Person","name":"Eyal-Shalev"},"datePublished":"2024-08-08T06:15:54Z","url":"https://github.com/python/typing/issues/1835"}
| 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:06692e04-91db-c91b-36ef-71045dcd7d60 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E034:34730F:24AE4F:2F7EBB:6AFF8401 |
| html-safe-nonce | 144c5789f083cdc03483723cdb60187c22a78849b9f738a5da6b3cfe21584d55 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDM0OjM0NzMwRjoyNEFFNEY6MkY3RUJCOjZBRkY4NDAxIiwidmlzaXRvcl9pZCI6Ijg5MjA0NTYzMjMyMDQ2MTMxMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 416e9dd008c7bc743d32057087f987dfcfc7fe25c63568813ac864caebb08ca9 |
| hovercard-subject-tag | issue:2454958518 |
| 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/typing/1835/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d7f48d4bba327e828bb5404e05ae02c45d3d28c46a64419f21bf70350ff5847/python/typing/issues/1835 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d7f48d4bba327e828bb5404e05ae02c45d3d28c46a64419f21bf70350ff5847/python/typing/issues/1835 |
| og:image:alt | Unknown Definition A type that can only be cast to Any Problem Currently when type checkers fail to understand the type of a function/variable, they fallback on Any. T = TypeVar("T") def foo(fn: Ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Eyal-Shalev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19488db4031f00b04ea79b4c70b5dd32cfa873a8d20b3877f3896b8e2d195946 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 7952f5285f4ba685d70c4c7540ad3cc9dc9746b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width