Title: Add a strictness flag that disables the bivariant behavior of `TypeGuard` · Issue #11230 · python/mypy · GitHub
Open Graph Title: Add a strictness flag that disables the bivariant behavior of `TypeGuard` · Issue #11230 · python/mypy
X Title: Add a strictness flag that disables the bivariant behavior of `TypeGuard` · Issue #11230 · python/mypy
Description: from typing import TypeGuard def is_str_list(val: list[object]) -> TypeGuard[list[str]]: return all(isinstance(x, str) for x in val) l1: list[object] = [] l2 = l1 if is_str_list(l1): l2.append(1) impostor: str = l1[0] # SUS ALERT!!!! 😳😳😳...
Open Graph Description: from typing import TypeGuard def is_str_list(val: list[object]) -> TypeGuard[list[str]]: return all(isinstance(x, str) for x in val) l1: list[object] = [] l2 = l1 if is_str_list(l1): l2.append(1) i...
X Description: from typing import TypeGuard def is_str_list(val: list[object]) -> TypeGuard[list[str]]: return all(isinstance(x, str) for x in val) l1: list[object] = [] l2 = l1 if is_str_list(l1): l2.append(1...
Opengraph URL: https://github.com/python/mypy/issues/11230
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a strictness flag that disables the bivariant behavior of `TypeGuard`","articleBody":"```py\r\nfrom typing import TypeGuard\r\n\r\n\r\ndef is_str_list(val: list[object]) -> TypeGuard[list[str]]:\r\n return all(isinstance(x, str) for x in val)\r\n\r\nl1: list[object] = []\r\nl2 = l1\r\n\r\nif is_str_list(l1):\r\n l2.append(1)\r\n impostor: str = l1[0] # SUS ALERT!!!! 😳😳😳😳😳😳😳\r\n```\r\n\r\nI can't stand bivariance, and I believe it should always be an opt-in behavior. I don't know any other place in python typing where bivariance exists (except for an `Any` generic parameter).\r\n\r\nPlease add a strictness flag that enforces standard python typing variance rules on `TypeGuard`.","author":{"url":"https://github.com/KotlinIsland","@type":"Person","name":"KotlinIsland"},"datePublished":"2021-09-30T05:34:59Z","url":"https://github.com/python/mypy/issues/11230"}
| 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:77fa6cc4-215f-9144-9f9f-24534d3d3bb7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A96A:2573D7:2352248:302C116:6B002EA3 |
| html-safe-nonce | b165f7cedc5637c978fdda301adfa77f8e1a42f71c50ee544f1d16c792248a33 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTZBOjI1NzNENzoyMzUyMjQ4OjMwMkMxMTY6NkIwMDJFQTMiLCJ2aXNpdG9yX2lkIjoiNjU4ODg2NjM0NjU1NjA3NTY4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6207fb6474adf39bed58f5b38a99fecdd694d0a04060f1335f7dfcb2af9f1002 |
| hovercard-subject-tag | issue:1011726890 |
| 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/11230/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af0c835006de3c486bce9492999e4920982512332fc5f9e2c35b47a77e6b9122/python/mypy/issues/11230 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af0c835006de3c486bce9492999e4920982512332fc5f9e2c35b47a77e6b9122/python/mypy/issues/11230 |
| og:image:alt | from typing import TypeGuard def is_str_list(val: list[object]) -> TypeGuard[list[str]]: return all(isinstance(x, str) for x in val) l1: list[object] = [] l2 = l1 if is_str_list(l1): l2.append(1) i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KotlinIsland |
| 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