Skip to content

import.metadata overview missing import statement #142197

Closed

Description

@lubianat

Documentation

Going through https://docs.python.org/3/library/importlib.metadata.html#overview I was following

You can get the :ref:`metadata for a distribution <metadata>`::
>>> list(metadata('wheel')) # doctest: +SKIP
['Metadata-Version', 'Name', 'Version', 'Summary', 'Home-page', 'Author', 'Author-email', 'Maintainer', 'Maintainer-email', 'License', 'Project-URL', 'Project-URL', 'Project-URL', 'Keywords', 'Platform', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Requires-Python', 'Provides-Extra', 'Requires-Dist', 'Requires-Dist']

and got as a result

>>> list(metadata('wheel'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'metadata' is not defined
>>> from importlib.metadata import metadata
>>> list(metadata('wheel'))
['Metadata-Version', 'Name', 'Version', 'Summary', 'Keywords', 'Author-email', 'Maintainer-email', 'Requires-Python', 'Description-Content-Type', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Requires-Dist', 'Requires-Dist', 'Project-URL', 'Project-URL', 'Project-URL', 'Project-URL', 'Provides-Extra', 'Description']

It could make sense to add from importlib.metadata import metadata to the docs.

Cheers,
Tiago

Linked PRs

Activity

  1. StanFromIreland commented on Dec 2, 2025

    @StanFromIreland
    Member

    From my reading the section is a step-by-step guide, and the import is in the previous step, and so, repeating it is not necessary. If we were to include the setup in each codeblock, it seems like we should include the venv creation and python -m pip install wheel too?

  2. lubianat commented on Dec 2, 2025

    @lubianat
    Author

    @StanFromIreland I was follwing it as a step-by-step guide indeed, but the previous codeblock imports only version, but not metadata. It is easy to figure out, so not a big blocker, but explicit is better than implict :)

    It could be changed to import both on the previous line too, to

    from importlib.metadata import version, metadata

    but that is maybe less intuitive given the context

  3. StanFromIreland commented on Dec 2, 2025

    @StanFromIreland
    Member

    Ah, I had not read closely enough, thank you. Yes I agree we should update it.

  4. Yashp002 commented on Dec 3, 2025

    @Yashp002
    Contributor

    I'd like to take this one. The fix should be straightforward - adding from importlib.metadata import metadata before the example code in the overview section. I'll submit a PR shortly.

  5. added a commit that references this issue on Sep 10, 2026
  6. added 2 commits that reference this issue on Sep 10, 2026
  7. added a commit that references this issue on Sep 11, 2026
  8. added a commit that references this issue on Sep 12, 2026
  9. added a commit that references this issue on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions