René's URL Explorer Experiment


Title: Return type annotation for `importlib.metadata.version` is incorrect · Issue #7513 · python/typeshed · GitHub

Open Graph Title: Return type annotation for `importlib.metadata.version` is incorrect · Issue #7513 · python/typeshed

X Title: Return type annotation for `importlib.metadata.version` is incorrect · Issue #7513 · python/typeshed

Description: To my surprise, I discovered in matrix-org/synapse#12223 that it is possible for importlib.metadata.version("foo") to return None. However, the stub suggests version and Distribution.version will always return a string: typeshed/stdlib/i...

Open Graph Description: To my surprise, I discovered in matrix-org/synapse#12223 that it is possible for importlib.metadata.version("foo") to return None. However, the stub suggests version and Distribution.version will a...

X Description: To my surprise, I discovered in matrix-org/synapse#12223 that it is possible for importlib.metadata.version("foo") to return None. However, the stub suggests version and Distribution.vers...

Opengraph URL: https://github.com/python/typeshed/issues/7513

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Return type annotation for `importlib.metadata.version` is incorrect","articleBody":"To my surprise, I discovered in https://github.com/matrix-org/synapse/issues/12223 that it is possible for `importlib.metadata.version(\"foo\")` to return `None`. However, the stub suggests `version` and `Distribution.version` will always return a string:\r\n\r\nhttps://github.com/python/typeshed/blob/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b/stdlib/importlib/metadata/__init__.pyi#L161\r\n\r\nhttps://github.com/python/typeshed/blob/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b/stdlib/importlib/metadata/__init__.pyi#L213\r\n\r\nTo prove that `version` sometimes returns `None`:\r\n\r\n1. Create a new virtual environment. I'm using CPython 3.10.2 as my interpreter.\r\n2. Within the venv, `pip install bottle`. (Any package will do; I choose `bottle` because it's small and doesn't have any dependencies).\r\n3. The `version` of `bottle` agrees with what you've just installed:\r\n    ```shell\r\n    $ python -c \"import importlib.metadata as m; print(repr(m.version('bottle')))\"\r\n    '0.12.19'\r\n    ````\r\n4. Here's the dirty bit: remove the metadata files for that package but keep the metadata directory.\r\n    - Use `pip show bottle` to find the `site-packages` location\r\n    - From there, remove all files in the `bottle-VERSION-.dist-info` directory: `rm /path/to/site-packages/bottle-VERSION.dist-info/*'.\r\n5. The `version` of `bottle` is now judged to be `None`:\r\n    ```shell\r\n    $ python -c \"import importlib.metadata as m; print(repr(m.version('bottle')))\"\r\n    None\r\n    ````\r\n\r\nA few other notes:\r\n- For a package `foo` that's not installed, `version(\"foo\") raises a PackageNotFoundError`.\r\n- I don't know if this ought to be considered a bug in the library rather than the annotations?\r\n- I haven't dug much into the internals of `importlib.metadata` but it looks like the version is retrieved by looking inside a `metadata` attribute on a `Distribution`. I think other lookups are vulnerable to a similar problem; the only example I could find is `Distribution.name`.\r\n\r\n","author":{"url":"https://github.com/DMRobertson","@type":"Person","name":"DMRobertson"},"datePublished":"2022-03-18T17:37:34Z","url":"https://github.com/python/typeshed/issues/7513"}

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:a324e904-fa98-4a23-8edf-ed4be44e9f94
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9EAA:220721:2AC5B4:3AE1FF:6B008804
html-safe-nonce757fcf45522c04b6c61272391e62de950163f060f01e5da3a7628754f77caf43
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUFBOjIyMDcyMToyQUM1QjQ6M0FFMUZGOjZCMDA4ODA0IiwidmlzaXRvcl9pZCI6IjE4OTQyNDM2MzI0NDY1MjU0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3f87d0f7a61b8c3cd19dbcbd6b73904f0aa39b26d31a04697ec32c17efaad25d
hovercard-subject-tagissue:1173847176
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/typeshed/7513/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9fbabe5b0b58f09d6074fdf9b82a19390b44f3e64840140b34c3ea9e522040bf/python/typeshed/issues/7513
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9fbabe5b0b58f09d6074fdf9b82a19390b44f3e64840140b34c3ea9e522040bf/python/typeshed/issues/7513
og:image:altTo my surprise, I discovered in matrix-org/synapse#12223 that it is possible for importlib.metadata.version("foo") to return None. However, the stub suggests version and Distribution.version will a...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDMRobertson
hostnamegithub.com
expected-hostnamegithub.com
None4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61
turbo-cache-controlno-preview
go-importgithub.com/python/typeshed git https://github.com/python/typeshed.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id31696383
octolytics-dimension-repository_nwopython/typeshed
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id31696383
octolytics-dimension-repository_network_root_nwopython/typeshed
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
releasedb758f8e02b8257935fb03edf81a3e76eb3abd11
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/typeshed/issues/7513#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftypeshed%2Fissues%2F7513
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%2Ftypeshed%2Fissues%2F7513
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%2Ftypeshed
Reloadhttps://github.com/python/typeshed/issues/7513
Reloadhttps://github.com/python/typeshed/issues/7513
Reloadhttps://github.com/python/typeshed/issues/7513
pythonhttps://github.com/python
typeshedhttps://github.com/python/typeshed
Codehttps://github.com/python/typeshed
Issues196 (196)https://github.com/python/typeshed/issues
Pull requests254 (254)https://github.com/python/typeshed/pulls
Actionshttps://github.com/python/typeshed/actions
Security and qualityhttps://github.com/python/typeshed/security
Insightshttps://github.com/python/typeshed/insights
https://github.com/python/typeshed
New issuehttps://github.com/login?return_to=https://github.com/python/typeshed/issues/7513
New issuehttps://github.com/login?return_to=https://github.com/python/typeshed/issues/7513
Return type annotation for importlib.metadata.version is incorrecthttps://github.com/python/typeshed/issues/7513#top
https://github.com/DMRobertson
DMRobertsonhttps://github.com/DMRobertson
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issue-1173847176
matrix-org/synapse#12223https://github.com/matrix-org/synapse/issues/12223
typeshed/stdlib/importlib/metadata/__init__.pyihttps://github.com/python/typeshed/blob/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b/stdlib/importlib/metadata/__init__.pyi#L161
50107e6https://github.com/python/typeshed/commit/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b
typeshed/stdlib/importlib/metadata/__init__.pyihttps://github.com/python/typeshed/blob/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b/stdlib/importlib/metadata/__init__.pyi#L213
50107e6https://github.com/python/typeshed/commit/50107e6e2b7144a1b0bfe6d46a7bc81926deed2b
https://github.com/DMRobertson
DMRobertsonhttps://github.com/DMRobertson
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072643409
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072649212
https://docs.python.org/3.10/library/importlib.metadata.html#distribution-versionshttps://docs.python.org/3.10/library/importlib.metadata.html#distribution-versions
https://github.com/DMRobertson
DMRobertsonhttps://github.com/DMRobertson
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072652951
https://docs.python.org/3.10/library/importlib.metadata.html#distribution-versionshttps://docs.python.org/3.10/library/importlib.metadata.html#distribution-versions
https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.versionhttps://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.version
DMRobertsonhttps://github.com/DMRobertson
completedhttps://github.com/python/typeshed/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#event-6267847889
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072654441
https://github.com/AlexWaygood
AlexWaygoodhttps://github.com/AlexWaygood
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072657774
https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.versionhttps://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.version
https://github.com/DMRobertson
DMRobertsonhttps://github.com/DMRobertson
on Mar 18, 2022https://github.com/python/typeshed/issues/7513#issuecomment-1072668871
https://bugs.python.org/issue47060https://bugs.python.org/issue47060
python/importlib_metadata#371https://github.com/python/importlib_metadata/issues/371
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/typeshed/issues/7513
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/typeshed/issues/7513
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.