Repository navigation
Conversation
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>
Documentation build overview
7 files changed ·
|
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>
jaraco
commented
Oct 22, 2026
jaraco
commented
Oct 22, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documents the interaction between a custom provider and the
importlib_metadatabackport, built around the protocols both librariessatisfy.
The two libraries define separate, unrelated class hierarchies but discover
distributions through the same
sys.meta_path, so one provider servesconsumers of both and cannot satisfy both by subclassing. The protocols, not
any concrete class, are the interface to write against.
for custom providers.
IDistributionandIPackagePath.PackageMetadataentry. It currently calls itself "a concreteimplementation of the PackageMetadata protocol" and links to the backport's
docs for the protocol, but
importlib.metadata._meta.PackageMetadataisitself a
Protocol, and is exported in__all__.DatabaseDistributionexample to the provider guidance.Assumes two things that have not landed
python/importlib_metadata#505. Released
importlib_metadata(9.0.1) hasno
localizemodule, so today there is no substitution and no warning todocument. The text describes 505 as of 3130095:
localize.dist/localize.message/localize.package_path, and theUserWarningraisedwhen a provider's class omits members
IDistributionrequires. Because thatwarning is decided by conformance rather than by class identity, a provider
deriving from
Distributionand inheriting the rest of the interface — theexample in these docs — draws no warning.
The protocols in this module.
IDistributionandIPackagePatharedocumented here with
.. versionadded:: 3.16, but no such change toLib/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_checkableand the stdlib's existingPackageMetadataandSimplePathare not, which the code change would needto reconcile for the conformance check.
Assumed, but not documented as such: that only the protocols come to the
stdlib. The
localizemachinery and its warning stay backport behavior, sincethis module has no reason to convert the backport's objects and cannot import
it to try.
🤖 Generated with Claude Code