Skip to content

gh-123976: Document the protocols shared with the importlib_metadata backport - #160344

Draft
jaraco wants to merge 4 commits into
python:mainfrom
jaraco:docs/gh-123976-backport-caveats
Draft

jaraco wants to merge 4 commits into
python:mainfrom
jaraco:docs/gh-123976-backport-caveats

Conversation

@jaraco

@jaraco jaraco commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Documents the interaction between a custom provider and the
importlib_metadata backport, built around the protocols both libraries
satisfy.

The two libraries define separate, unrelated class hierarchies but discover
distributions through the same sys.meta_path, so one provider serves
consumers of both and cannot satisfy both by subclassing. The protocols, not
any concrete class, are the interface to write against.

  • New "Caveats for backports" section, split into guidance for consumers and
    for custom providers.
  • Documents IDistribution and IPackagePath.
  • Corrects the PackageMetadata entry. It currently calls itself "a concrete
    implementation of the PackageMetadata protocol" and links to the backport's
    docs for the protocol, but importlib.metadata._meta.PackageMetadata is
    itself a Protocol, and is exported in __all__.
  • Points from the DatabaseDistribution example to the provider guidance.

Assumes two things that have not landed

python/importlib_metadata#505. Released importlib_metadata (9.0.1) has
no localize module, so today there is no substitution and no warning to
document. The text describes 505 as of 3130095: localize.dist /
localize.message / localize.package_path, and the UserWarning raised
when a provider's class omits members IDistribution requires. Because that
warning is decided by conformance rather than by class identity, a provider
deriving from Distribution and inheriting the rest of the interface — the
example in these docs — draws no warning.

The protocols in this module. IDistribution and IPackagePath are
documented here with .. versionadded:: 3.16, but no such change to
Lib/importlib/metadata/ exists yet; today they live only in the backport.
This PR is docs-only and must not land before that change does. Note the
backport's protocols are @runtime_checkable and the stdlib's existing
PackageMetadata and SimplePath are not, which the code change would need
to reconcile for the conformance check.

Assumed, but not documented as such: that only the protocols come to the
stdlib. The localize machinery and its warning stay backport behavior, since
this module has no reason to convert the backport's objects and cannot import
it to try.

🤖 Generated with Claude Code

Describe how the separate class hierarchies in importlib.metadata and
the importlib_metadata backport affect custom providers: which objects
the backport substitutes, which it passes through with a warning, and
why a provider should implement the whole interface and rely on the
shared protocols rather than on a particular base class.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35338294 | 📁 Comparing be9a5de against main (e7e0b35)

  🔍 Preview build  

7 files changed · ± 7 modified

± Modified

importlib_metadata now decides the warning by conformance to
IDistribution rather than by class identity, so a provider that
presents the whole interface draws no warning and the warning names
what a class omits.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread Doc/library/importlib.metadata.rst Outdated
Comment thread Doc/library/importlib.metadata.rst Outdated
jaraco and others added 2 commits October 22, 2026 14:51
The guidance to rely on the interface rather than the type addresses
every consumer, not only a provider that consumes metadata, so promote
the caveats to their own section and split it by audience. Note that
the protocols come from the backport, which this module does not yet
present.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Assume the shared protocols from python/importlib_metadata#505 are
presented by this module as well: document IDistribution and
IPackagePath, correct PackageMetadata, which is already a protocol here
rather than an implementation of the backport's, and write the caveats
around the protocols as the interface both libraries satisfy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jaraco jaraco changed the title gh-123976: Document backport caveats for custom providers gh-123976: Document the protocols shared with the importlib_metadata backport Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant