René's URL Explorer Experiment


Title: TypeGuard type narrowing on returning False · Issue #996 · python/typing · GitHub

Open Graph Title: TypeGuard type narrowing on returning False · Issue #996 · python/typing

X Title: TypeGuard type narrowing on returning False · Issue #996 · python/typing

Description: I've faced limitation of not narrowing types when trying to add types in https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33 - (np.isscalar)[https://numpy.org/doc/stable/reference/generated/n...

Open Graph Description: I've faced limitation of not narrowing types when trying to add types in https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33 - (np.isscalar)[https://nu...

X Description: I've faced limitation of not narrowing types when trying to add types in https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33 - (np.isscalar)[https:...

Opengraph URL: https://github.com/python/typing/issues/996

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeGuard type narrowing on returning False","articleBody":"\u003c!-- Please describe the problem you face as well as your idea below, ideally using examples for both. -->\r\n\r\nI've faced limitation of not narrowing types when trying to add types in https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33 - (np.isscalar)[https://numpy.org/doc/stable/reference/generated/numpy.isscalar.html] returning False rules out `SupportsFloat` type, and given input type `SupportsFloat | np.ndarray` I now know it was narrowed down to np.ndarray.\r\n\r\nNumpy has not added type guard yet in its stub, but this is the logical type for this function once all supported python versions will have it. Yet with current syntax it's not possible to describe the function narrowing type by returning False.\r\n\r\nProposal: give TypeGuard second optional argument: TypeGuard[A, B] should narrow argument type A | B to A if returning True, and to B if returning False. Old syntax should still work, where one can have TypeGuard[A] work as it does currently.\r\n\r\nI didn't find this in rejected ideas of https://www.python.org/dev/peps/pep-0647/, so wanted to share. I'm not sure how much of stdlib could use this, but it definitely helps to be able to write function in the most semantically convenient way. I can express both \"is_x\" and \"is_not_x\" function in typesystem if this is added. This could have synergy with NonType currently being discussed.\r\n\r\nUnclear yet: how best to describe situation where no type narrowing occurs on True return, but only on False. Maybe `TypeGuard[Any, B] ` could have this semantics.\r\n","author":{"url":"https://github.com/ikamensh","@type":"Person","name":"ikamensh"},"datePublished":"2021-12-27T15:44:57Z","url":"https://github.com/python/typing/issues/996"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ef5fbb64-1ba8-592d-c28a-ffc1ffc7f824
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD436:16AB79:4F12DCB:6431E4D:6B026E41
html-safe-nonce5daf99801c2c8c60937abfb3a7b6504b9f02d5db697d7368a10c4e05472809d0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDM2OjE2QUI3OTo0RjEyRENCOjY0MzFFNEQ6NkIwMjZFNDEiLCJ2aXNpdG9yX2lkIjoiNzEwNzY4MTM4MzU0NzU2MzU4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf5f6c2b6d7fea69ceb43ea55d2e3509957e6687f9be5e4a245b0cc4c471efb06
hovercard-subject-tagissue:1089322627
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/996/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1d133522eeaf556ff4d0520d551b5e128d29a3e0830358ac59a3d81768e6190d/python/typing/issues/996
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1d133522eeaf556ff4d0520d551b5e128d29a3e0830358ac59a3d81768e6190d/python/typing/issues/996
og:image:altI've faced limitation of not narrowing types when trying to add types in https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33 - (np.isscalar)[https://nu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameikamensh
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/typing git https://github.com/python/typing.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id24604008
octolytics-dimension-repository_nwopython/typing
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24604008
octolytics-dimension-repository_network_root_nwopython/typing
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typing/issues/996#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F996
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftyping%2Fissues%2F996
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Ftyping
Reloadhttps://github.com/python/typing/issues/996
Reloadhttps://github.com/python/typing/issues/996
Reloadhttps://github.com/python/typing/issues/996
pythonhttps://github.com/python
typinghttps://github.com/python/typing
Codehttps://github.com/python/typing
Issues206 (206)https://github.com/python/typing/issues
Pull requests27 (27)https://github.com/python/typing/pulls
Discussionshttps://github.com/python/typing/discussions
Actionshttps://github.com/python/typing/actions
Security and qualityhttps://github.com/python/typing/security
Insightshttps://github.com/python/typing/insights
https://github.com/python/typing
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/996
New issuehttps://github.com/login?return_to=https://github.com/python/typing/issues/996
TypeGuard type narrowing on returning Falsehttps://github.com/python/typing/issues/996#top
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com/ikamensh
ikamenshhttps://github.com/ikamensh
on Dec 27, 2021https://github.com/python/typing/issues/996#issue-1089322627
https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33https://github.com/openai/gym/blob/8e5ae02ab13a89c976ce7b1278c21f755dfa4bd2/gym/spaces/box.py#L33
https://www.python.org/dev/peps/pep-0647/https://www.python.org/dev/peps/pep-0647/
ikamenshhttps://github.com/ikamensh
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
on Dec 27, 2021https://github.com/python/typing/issues/996#event-5818345957
https://github.com/Gobot1234
Gobot1234https://github.com/Gobot1234
on Dec 27, 2021https://github.com/python/typing/issues/996#issuecomment-1001631414
#926https://github.com/python/typing/issues/926
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 28, 2021https://github.com/python/typing/issues/996#issuecomment-1001979242
https://github.com/ikamensh
ikamenshhttps://github.com/ikamensh
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002482628
np.isscalarhttps://numpy.org/doc/stable/reference/generated/numpy.isscalar.html
https://github.com/ikamensh
ikamenshhttps://github.com/ikamensh
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002487805
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002516450
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002716830
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002728309
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 29, 2021https://github.com/python/typing/issues/996#issuecomment-1002737704
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 30, 2021https://github.com/python/typing/issues/996#issuecomment-1002837315
https://github.com/erictraut
erictrauthttps://github.com/erictraut
on Dec 30, 2021https://github.com/python/typing/issues/996#issuecomment-1003122884
https://mail.python.org/archives/list/typing-sig@python.org/thread/EMUD2D424OI53DCWQ4H5L6SJD2IXBHUL/https://mail.python.org/archives/list/typing-sig@python.org/thread/EMUD2D424OI53DCWQ4H5L6SJD2IXBHUL/
https://github.com/ikamensh
ikamenshhttps://github.com/ikamensh
on Jan 7, 2022https://github.com/python/typing/issues/996#issuecomment-1007318231
https://github.com/MajorDallas
MajorDallashttps://github.com/MajorDallas
on Jan 13, 2022https://github.com/python/typing/issues/996#issuecomment-1012314751
PEP-647https://peps.python.org/647
https://github.com/alythobani
alythobanihttps://github.com/alythobani
on Apr 10, 2025https://github.com/python/typing/issues/996#issuecomment-2791362314
#926https://github.com/python/typing/issues/926
#926https://github.com/python/typing/issues/926
closedhttps://github.com/python/typing/issues/926#issuecomment-2116598603
@erictrauthttps://github.com/erictraut
erictrauthttps://github.com/erictraut
completedhttps://github.com/python/typing/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Apr 10, 2025https://github.com/python/typing/issues/996#event-17198246816
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typing/issues/996
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typing/issues/996
topic: featureDiscussions about new features for Python's type annotationshttps://github.com/python/typing/issues?q=state%3Aopen%20label%3A%22topic%3A%20feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.