Title: Change PEP 647 to allow for narrowing in the negative case · Issue #926 · python/typing · GitHub
Open Graph Title: Change PEP 647 to allow for narrowing in the negative case · Issue #926 · python/typing
X Title: Change PEP 647 to allow for narrowing in the negative case · Issue #926 · python/typing
Description: Currently PEP 647 doesnt narrow the type in the negative case, i feel like this should be changed to narrow in the negative case, currently due to it not narrowing its impossible to correctly type certain functions with typeguards fully,...
Open Graph Description: Currently PEP 647 doesnt narrow the type in the negative case, i feel like this should be changed to narrow in the negative case, currently due to it not narrowing its impossible to correctly type ...
X Description: Currently PEP 647 doesnt narrow the type in the negative case, i feel like this should be changed to narrow in the negative case, currently due to it not narrowing its impossible to correctly type ...
Opengraph URL: https://github.com/python/typing/issues/926
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Change PEP 647 to allow for narrowing in the negative case","articleBody":"Currently [PEP 647](https://www.python.org/dev/peps/pep-0647/) doesnt narrow the type in the negative case, i feel like this should be changed to narrow in the negative case, currently due to it not narrowing its impossible to correctly type certain functions with typeguards fully, this came up in actual code a couple times, for example:\r\n\r\nthis example is used in conjuction with https://github.com/python/typeshed/pull/5658\r\n```py\r\nR_T = TypeVar(\"R_T\")\r\nP = ParamSpec(\"P\")\r\n\r\nasync def maybe_coroutine(func: Callable[P, Union[R_T, Coroutine[Any, Any, R_T]]], *args: P.args, **kwargs: P.kwargs) -> R_T:\r\n value = func(*args, **kwargs)\r\n\r\n if isawaitable(value):\r\n value = await value\r\n\r\n return value\r\n```\r\nbecause `value` isnt narrowed to be `R_T@maybe_coroutine` outside the if statement its back to being a union even though it would never be awaitable because of the if statement, this feels like a massive downside and makes typeguard pretty useless for a lot of cases, forcing people to use `cast` or `# type: ignore`.\r\n\r\nWhile this may cause a lot of controversy with changing a quite large part of how typeguards work, i feel like this is a needed change and a step in the right direction for making typing much more powerful and able to be properly integrated into more projects codebases without having to resort to ignoring or overwrites the type","author":{"url":"https://github.com/Zomatree","@type":"Person","name":"Zomatree"},"datePublished":"2021-11-06T03:10:55Z","url":"https://github.com/python/typing/issues/926"}
| 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:dd190e88-de22-89b0-dbdc-6bbda8b4fdee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9116:25866C:E7D5E3:12E79D1:6B027C58 |
| html-safe-nonce | c5d0d882059876ae2d2743e426c46d3caf11fa488cedebed38d2ed056a36e4a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTE2OjI1ODY2QzpFN0Q1RTM6MTJFNzlEMTo2QjAyN0M1OCIsInZpc2l0b3JfaWQiOiIyOTQ0MzQyNjI0NTc3OTQ0NjY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 477b0c6371138061550df32b905ee2238b9f777719aed81a99fd044962db3b00 |
| hovercard-subject-tag | issue:1046375457 |
| 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/926/issue_layout |
| twitter:image | https://opengraph.githubassets.com/21d14bb5de1c386ad1b977f109d626ca0920b0522d38fe27426a707d266fca8b/python/typing/issues/926 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/21d14bb5de1c386ad1b977f109d626ca0920b0522d38fe27426a707d266fca8b/python/typing/issues/926 |
| og:image:alt | Currently PEP 647 doesnt narrow the type in the negative case, i feel like this should be changed to narrow in the negative case, currently due to it not narrowing its impossible to correctly type ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Zomatree |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width