René's URL Explorer Experiment


Title: Simple dependent types · Issue #3062 · python/mypy · GitHub

Open Graph Title: Simple dependent types · Issue #3062 · python/mypy

X Title: Simple dependent types · Issue #3062 · python/mypy

Description: [This is based on a discussion between me and @gvanrossum last week. I'm writing this down so that we won't forget about this.] Several stdlib functions have signatures where the return type depends on the value of an argument. Examples:...

Open Graph Description: [This is based on a discussion between me and @gvanrossum last week. I'm writing this down so that we won't forget about this.] Several stdlib functions have signatures where the return type depend...

X Description: [This is based on a discussion between me and @gvanrossum last week. I'm writing this down so that we won't forget about this.] Several stdlib functions have signatures where the return typ...

Opengraph URL: https://github.com/python/mypy/issues/3062

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Simple dependent types","articleBody":"[This is based on a discussion between me and @gvanrossum last week. I'm writing this down so that we won't forget about this.]\r\n\r\nSeveral stdlib functions have signatures where the return type depends on the value of an argument. Examples:\r\n\r\n* `open` returns an `IO[str]` or `IO[bytes]` depending on whether the mode argument has `'b'` as a substring.\r\n* `subprocess.check_output` returns a `str` or `bytes` depending on the value of the boolean `universal_newlines` argument.\r\n\r\nA simple way to support these would be to introduce a few additional types that work with `str` and `bool` literals:\r\n\r\n* A string pattern type that can describe the contents of a string literal, perhaps using a regular expression.\r\n* Types for `False` and `True`.\r\n\r\nFor example, if we had `FalseType` and `TrueType`, we could write a function whose return value depends on the value of a boolean argument:\r\n\r\n```py\r\n@overload\r\ndef f(x: FalseType) -> bytes: ...\r\n@overload\r\ndef f(x: TrueType) -> str: ...\r\n\r\ndef f(x: Any) -> Any:\r\n    if x:\r\n        return 'x'\r\n    else:\r\n        return b'x'\r\n\r\nreveal_type(f(False))  # bytes\r\nreveal_type(f(True)  # str\r\n```\r\n\r\nNot sure about this one:\r\n\r\n```py\r\n...\r\nx = bool('')\r\nreveal_type(f(x))  # Union[str, bytes] since we don't know the boolean value statically?\r\n```\r\n\r\nWe could also have a generic class where a generic type argument depends on the value of an argument to `__init__`. Not sure how we should represent these -- here is one potential approach:\r\n\r\n```py\r\nclass C(Generic[AnyStr]):\r\n    @overload\r\n    @returntype('C[str]')\r\n    def __init__(self, x: TrueType) -> None: ...\r\n    @overload\r\n    @returntype('C[bytes]')\r\n    def __init__(self, x: FalseType) -> None: ...\r\n    ...\r\n\r\nreveal_type(C(True))  # C[str]\r\n```\r\n\r\nAlternatively, we could use `__new__`, but this would be problematic if there is no corresponding method defined at runtime.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2017-03-27T16:15:38Z","url":"https://github.com/python/mypy/issues/3062"}

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:c81687fe-c9b4-c590-8fb5-d0bd09236971
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDF2A:3CBF1A:1E7E670:29B1D27:6B001DE5
html-safe-nonce0f83ee63040707b38941fc3d915486096d5c6cfb731cc0ae1163dcd7bb89cd5f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjJBOjNDQkYxQToxRTdFNjcwOjI5QjFEMjc6NkIwMDFERTUiLCJ2aXNpdG9yX2lkIjoiODU1MDk5MTY2MTQ2NTg2OTc5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace34efa2d6bc642331194b6d5526d1368288fe2ccee2f8d8d2de8899ea8f93464
hovercard-subject-tagissue:217298527
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/mypy/3062/issue_layout
twitter:imagehttps://opengraph.githubassets.com/458592416ea87722b2a4723ccad8156cb6932c20204959dbaa0da3eeaf5e1e13/python/mypy/issues/3062
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/458592416ea87722b2a4723ccad8156cb6932c20204959dbaa0da3eeaf5e1e13/python/mypy/issues/3062
og:image:alt[This is based on a discussion between me and @gvanrossum last week. I'm writing this down so that we won't forget about this.] Several stdlib functions have signatures where the return type depend...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJukkaL
hostnamegithub.com
expected-hostnamegithub.com
None4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
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
release44c658b24abf00491fb7ae5f56d42c9f38cbeab2
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/3062#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F3062
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%2Fmypy%2Fissues%2F3062
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%2Fmypy
Reloadhttps://github.com/python/mypy/issues/3062
Reloadhttps://github.com/python/mypy/issues/3062
Reloadhttps://github.com/python/mypy/issues/3062
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests546 (546)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/3062
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/3062
Simple dependent typeshttps://github.com/python/mypy/issues/3062#top
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%22
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issue-217298527
@gvanrossumhttps://github.com/gvanrossum
Nexthttps://github.com/python/mypy/issues/3062?timeline_page=1
JukkaLhttps://github.com/JukkaL
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%22
on Mar 27, 2017https://github.com/python/mypy/issues/3062#event-1016984575
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289592112
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289593982
@JukkaLhttps://github.com/JukkaL
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289601645
https://github.com/sixolet
sixolethttps://github.com/sixolet
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289601665
…https://github.com/python/mypy/issues/3062
@JukkaLhttps://github.com/JukkaL
https://github.com/JukkaLhttps://github.com/JukkaL
#3062 (comment)https://github.com/python/mypy/issues/3062#issuecomment-289593982
https://github.com/notifications/unsubscribe-auth/ABjs4Q_pmhJYnbeMNorZzX3OAIZpKeCzks5rqCw1gaJpZM4Mqfj6https://github.com/notifications/unsubscribe-auth/ABjs4Q_pmhJYnbeMNorZzX3OAIZpKeCzks5rqCw1gaJpZM4Mqfj6
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289601683
https://github.com/sixolet
sixolethttps://github.com/sixolet
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289602600
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289604272
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289604287
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Mar 27, 2017https://github.com/python/mypy/issues/3062#issuecomment-289605761
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 28, 2017https://github.com/python/mypy/issues/3062#issuecomment-289914483
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 28, 2017https://github.com/python/mypy/issues/3062#issuecomment-289927685
https://github.com/pkch
pkchhttps://github.com/pkch
on Mar 28, 2017https://github.com/python/mypy/issues/3062#issuecomment-289932221
@elazarghttps://github.com/elazarg
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Mar 28, 2017https://github.com/python/mypy/issues/3062#issuecomment-289933048
https://github.com/elazarg
elazarghttps://github.com/elazarg
on Mar 28, 2017https://github.com/python/mypy/issues/3062#issuecomment-289934748
https://typesandkinds.wordpress.com/#what-are-singletonshttps://typesandkinds.wordpress.com/#what-are-singletons
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Oct 30, 2018https://github.com/python/mypy/issues/3062#issuecomment-434357128
@mehdigmirahttps://github.com/mehdigmira
https://github.com/python/mypy/tree/master/mypy/pluginshttps://github.com/python/mypy/tree/master/mypy/plugins
https://github.com/mehdigmira
mehdigmirahttps://github.com/mehdigmira
on Oct 30, 2018https://github.com/python/mypy/issues/3062#issuecomment-434360911
@JukkaLhttps://github.com/JukkaL
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Oct 30, 2018https://github.com/python/mypy/issues/3062#issuecomment-434361727
@mehdigmirahttps://github.com/mehdigmira
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Oct 30, 2018https://github.com/python/mypy/issues/3062#issuecomment-434372933
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/srittau
srittauhttps://github.com/srittau
on Oct 30, 2018https://github.com/python/mypy/issues/3062#issuecomment-434380935
https://github.com/lubieowoce
lubieowocehttps://github.com/lubieowoce
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-434934940
typesafe printfhttps://gist.github.com/chrisdone/672efcd784528b7d0b7e17ad9c115292
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-434995377
@srittauhttps://github.com/srittau
@lubieowocehttps://github.com/lubieowoce
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-435002615
@JukkaLhttps://github.com/JukkaL
@Michael0x2ahttps://github.com/Michael0x2a
@lubieowocehttps://github.com/lubieowoce
@srittauhttps://github.com/srittau
https://github.com/brainrake
brainrakehttps://github.com/brainrake
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-435030995
@ilevkivskyihttps://github.com/ilevkivskyi
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-435043419
https://github.com/lubieowoce
lubieowocehttps://github.com/lubieowoce
on Nov 1, 2018https://github.com/python/mypy/issues/3062#issuecomment-435182102
@ilevkivskyihttps://github.com/ilevkivskyi
@JukkaLhttps://github.com/JukkaL
https://github.com/Michael0x2a
Michael0x2ahttps://github.com/Michael0x2a
on Nov 20, 2018https://github.com/python/mypy/issues/3062#issuecomment-440158798
https://github.com/Michael0x2a/peps/blob/literal-types/pep-9999.rsthttps://github.com/Michael0x2a/peps/blob/literal-types/pep-9999.rst
shiny new typing-sigs mailing listhttps://mail.python.org/mailman3/lists/typing-sig.python.org/
https://github.com/emmatyping
emmatypinghttps://github.com/emmatyping
on Jul 4, 2019https://github.com/python/mypy/issues/3062#issuecomment-508389578
@Michael0x2ahttps://github.com/Michael0x2a
#5935https://github.com/python/mypy/issues/5935
https://github.com/JukkaL
JukkaLhttps://github.com/JukkaL
on Jul 4, 2019https://github.com/python/mypy/issues/3062#issuecomment-508393208
JukkaLhttps://github.com/JukkaL
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 4, 2019https://github.com/python/mypy/issues/3062#event-2459844494
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/3062
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/3062
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%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.