René's URL Explorer Experiment


Title: Test stub files against real code · Issue #5028 · python/mypy · GitHub

Open Graph Title: Test stub files against real code · Issue #5028 · python/mypy

X Title: Test stub files against real code · Issue #5028 · python/mypy

Description: There are a few use cases when stubs may be compelling over type annotations or type comments: annotate code that needs to be Python 2 compatible, ideally by using type annotations (so no type comments), often times users prefer to have ...

Open Graph Description: There are a few use cases when stubs may be compelling over type annotations or type comments: annotate code that needs to be Python 2 compatible, ideally by using type annotations (so no type comm...

X Description: There are a few use cases when stubs may be compelling over type annotations or type comments: annotate code that needs to be Python 2 compatible, ideally by using type annotations (so no type comm...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Test stub files against real code","articleBody":"There are a few use cases when stubs may be compelling over type annotations or type comments:\r\n\r\n- annotate code that needs to be Python 2 compatible, ideally by using type annotations (so no type comments), \r\n- often times users prefer to have type information outside of the source code (this is to avoid modifying legacy code change - and in practice lowers resistance from maintainers),\r\n- the maintainer of the library does not want to take on the in-line type annotations, someone else trying to provide it as a separate package.\r\n\r\nHowever at the moment this has some limitations: stub files are used only to check clients of the stub, not the code itself. \r\n\r\n```python\r\n# a.py\r\ndef add_int(a, b):\r\n    return a + b\r\n\r\nadd_int(\"a\", \"b\") # mypy does not complain, actually ignores the entire file\r\n```\r\n\r\n```python\r\n# a.pyi\r\ndef add_int(a:int, b:int) -> int: ...\r\n```\r\n\r\n```python\r\n# client.py\r\nfrom a import add_int\r\nadd_int(1, 2)\r\nadd_int(1, \"2\") # here mypy is going to complain\r\n```\r\n\r\nIn case of the above files mypy will warn about bad usage of inside ``client.py``, but not in ``a.py`` (that is, mypy does not validate against the source files being annotated by the stub). This has serious drawbacks: \r\n- maintaining the stub files is hard, now users need to manually make sure whatever is in the stub file is an accurate representation of the matching source files (both interface - aka number of arguments, names - and type wise),\r\n- the stub creator does not know if the source code itself is type correct or not.\r\n\r\nHere I propose to implement a way to support testing stub files against the real code:\r\n\r\n- build the syntax tree for the source file,\r\n- build the syntax tree for the stub file, \r\n- merge stub tree into the source tree\r\n  - source file only tree available: dynamically typed - noop\r\n  - abstract syntax tree only: raise error - missing annotated sources\r\n  - both stub and source AST exists:\r\n    - for all source elements for what there is a matching stub element\r\n      - copy inject over type annotations\r\n      - complain if function interface missmatch\r\n- now just run the existing type checking mechanism on the enriched source code ast\r\n\r\nMerging the AST definitely is not trivial. The plan is to start with a POC implementation, that works for the most cases, and then see the viability of this approach. Note this would help a lot both stub maintainers I think (typeshed) and projects that need Python 2 support. ","author":{"url":"https://github.com/gaborbernat","@type":"Person","name":"gaborbernat"},"datePublished":"2018-05-13T18:18:48Z","url":"https://github.com/python/mypy/issues/5028"}

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:d095e848-8c00-4c2d-4784-90673c74a238
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA150:B7CF9:EFA2E9:14066E5:6B0057F8
html-safe-nonce1c4fffce91b8c4e13acf9709641ae6992eff7a981cb67fc5123eda1880e4fd68
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTUwOkI3Q0Y5OkVGQTJFOToxNDA2NkU1OjZCMDA1N0Y4IiwidmlzaXRvcl9pZCI6Ijg5ODU0Nzk2NTQxNjQ5NDQ4ODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac305cbb073318db8b2460e1f4dbc4f5687ecf3c67aaf21d1178c6dc9c1fdfef3f
hovercard-subject-tagissue:322615734
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/5028/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ee9ff349de1aa52588061416033cfea623ae91126b70318f59b6f7f74426dea5/python/mypy/issues/5028
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ee9ff349de1aa52588061416033cfea623ae91126b70318f59b6f7f74426dea5/python/mypy/issues/5028
og:image:altThere are a few use cases when stubs may be compelling over type annotations or type comments: annotate code that needs to be Python 2 compatible, ideally by using type annotations (so no type comm...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegaborbernat
hostnamegithub.com
expected-hostnamegithub.com
Nonef420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb
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
release26e00df917aba0f128135dc073ea0c5e33a70d40
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/5028#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F5028
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%2F5028
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/5028
Reloadhttps://github.com/python/mypy/issues/5028
Reloadhttps://github.com/python/mypy/issues/5028
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/5028
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/5028
Test stub files against real codehttps://github.com/python/mypy/issues/5028#top
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%22
priority-1-normalhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-1-normal%22
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on May 13, 2018https://github.com/python/mypy/issues/5028#issue-322615734
Nexthttps://github.com/python/mypy/issues/5028?timeline_page=1
gaborbernathttps://github.com/gaborbernat
on May 13, 2018https://github.com/python/mypy/issues/5028#event-1623650428
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on May 13, 2018https://github.com/python/mypy/issues/5028#issuecomment-388645965
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on May 13, 2018https://github.com/python/mypy/issues/5028#issuecomment-388646318
@gvanrossumhttps://github.com/gvanrossum
@JukkaLhttps://github.com/JukkaL
ilevkivskyihttps://github.com/ilevkivskyi
on May 14, 2018https://github.com/python/mypy/issues/5028#event-1623812238
ilevkivskyihttps://github.com/ilevkivskyi
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%22
priority-1-normalhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-1-normal%22
on May 14, 2018https://github.com/python/mypy/issues/5028#event-1623812447
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on May 17, 2018https://github.com/python/mypy/issues/5028#issuecomment-389927088
https://github.com/gaborbernat/mypy/commit/a56f007386daab9229af957ac252b3397146b8dchttps://github.com/gaborbernat/mypy/commit/a56f007386daab9229af957ac252b3397146b8dc
https://github.com/tox-dev/toxhttps://github.com/tox-dev/tox
https://github.com/mchlnix
mchlnixhttps://github.com/mchlnix
on Dec 17, 2018https://github.com/python/mypy/issues/5028#issuecomment-447691840
https://github.com/pcorpet
pcorpethttps://github.com/pcorpet
on Mar 1, 2019https://github.com/python/mypy/issues/5028#issuecomment-468621696
@gaborbernathttps://github.com/gaborbernat
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on Mar 1, 2019https://github.com/python/mypy/issues/5028#issuecomment-468625223
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on May 25, 2019https://github.com/python/mypy/issues/5028#issuecomment-495942769
https://github.com/ambv/retypehttps://github.com/ambv/retype
https://github.com/ambv/retype/blob/master/tox.ini#L53-L59https://github.com/ambv/retype/blob/master/tox.ini#L53-L59
https://github.com/ambv/retype/tree/master/typeshttps://github.com/ambv/retype/tree/master/types
https://github.com/ambv/retypehttps://github.com/ambv/retype
https://github.com/graingert
graingerthttps://github.com/graingert
on Dec 5, 2019https://github.com/python/mypy/issues/5028#issuecomment-562200791
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Dec 5, 2019https://github.com/python/mypy/issues/5028#issuecomment-562209620
https://github.com/dry-python/returns/blob/master/returns/generated/pipe.pyihttps://github.com/dry-python/returns/blob/master/returns/generated/pipe.pyi
https://github.com/dry-python/returns/blob/master/returns/generated/pipe.pyhttps://github.com/dry-python/returns/blob/master/returns/generated/pipe.py
https://github.com/mchlnix
mchlnixhttps://github.com/mchlnix
on Dec 6, 2019https://github.com/python/mypy/issues/5028#issuecomment-562508400
@graingerthttps://github.com/graingert
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Dec 7, 2020https://github.com/python/mypy/issues/5028#issuecomment-740101546
https://github.com/astrojuanlu
astrojuanluhttps://github.com/astrojuanlu
on Dec 7, 2020https://github.com/python/mypy/issues/5028#issuecomment-740123790
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Dec 7, 2020https://github.com/python/mypy/issues/5028#issuecomment-740126344
https://mypy.readthedocs.io/en/latest/stubtest.htmlhttps://mypy.readthedocs.io/en/latest/stubtest.html
https://github.com/davidism
davidismhttps://github.com/davidism
on Jan 10, 2021https://github.com/python/mypy/issues/5028#issuecomment-757511524
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Jan 10, 2021https://github.com/python/mypy/issues/5028#issuecomment-757536182
https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtimehttps://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
graingerthttps://github.com/graingert
on Jun 26, 2021https://github.com/python/mypy/issues/5028#event-4942887818
Actually run a typecheck in CIhttps://github.com/jazzband/contextlib2/commit/0fb391a30c14a85f8e3d1eca412b16311123e278
0fb391ahttps://github.com/jazzband/contextlib2/commit/0fb391a30c14a85f8e3d1eca412b16311123e278
https://github.com/ncoghlan
ncoghlanhttps://github.com/ncoghlan
on Jun 26, 2021https://github.com/python/mypy/issues/5028#issuecomment-869001339
@graingerthttps://github.com/graingert
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Jun 26, 2021https://github.com/python/mypy/issues/5028#issuecomment-869055259
https://github.com/graingert
graingerthttps://github.com/graingert
on Jun 26, 2021https://github.com/python/mypy/issues/5028#issuecomment-869056865
@hauntsaninjahttps://github.com/hauntsaninja
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on Jun 26, 2021https://github.com/python/mypy/issues/5028#issuecomment-869060990
https://github.com/python/typeshed/blob/50f5858a5628529b7a453c675e0f4b1eeccc704d/tests/stubtest_allowlists/py37.txt#L29https://github.com/python/typeshed/blob/50f5858a5628529b7a453c675e0f4b1eeccc704d/tests/stubtest_allowlists/py37.txt#L29
https://github.com/graingert
graingerthttps://github.com/graingert
on Jun 26, 2021https://github.com/python/mypy/issues/5028#issuecomment-869064720
https://github.com/ariba-05
ariba-05https://github.com/ariba-05
on May 15, 2023https://github.com/python/mypy/issues/5028#issuecomment-1547111987
LibCSThttps://libcst.readthedocs.io/en/latest/tutorial.html#Example:-add-typing-annotation-from-pyi-stub-file-to-Python-source
https://github.com/hauntsaninja
hauntsaninjahttps://github.com/hauntsaninja
on May 15, 2023https://github.com/python/mypy/issues/5028#issuecomment-1547135002
https://github.com/google/pytype/blob/main/pytype/tools/merge_pyi/merge_pyi.pyhttps://github.com/google/pytype/blob/main/pytype/tools/merge_pyi/merge_pyi.py
https://github.com/gaborbernat
gaborbernathttps://github.com/gaborbernat
on Sep 23, 2026https://github.com/python/mypy/issues/5028#issuecomment-5803552114
gaborbernathttps://github.com/gaborbernat
not plannedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Sep 23, 2026https://github.com/python/mypy/issues/5028#event-31712217957
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/5028
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/5028
featurehttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22feature%22
needs discussionhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22needs%20discussion%22
priority-1-normalhttps://github.com/python/mypy/issues?q=state%3Aopen%20label%3A%22priority-1-normal%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.