fix(api): avoid SelectableGroups.values() DeprecationWarning on Python 3.10/3.11#5255
Closed
me-saurabhkohli wants to merge 1 commit into
Conversation
…n 3.10/3.11 Fixes open-telemetry#5231. In v1.42.0, _as_entry_points() was added to normalise the return value of importlib.metadata.entry_points() across Python versions. On Python 3.10 and 3.11, entry_points() returns a SelectableGroups object whose dict interface is deprecated; iterating it via .values() unconditionally emits: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select. This turns into an error for projects that run their test suites with -W error (warnings-as-errors), which is a common CI configuration. Fix: prefer .select() (available on both SelectableGroups and the newer EntryPoints) over .values() when the object exposes it. This is the officially recommended migration path documented in importlib.metadata.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the entry points normalization helper to avoid DeprecationWarning on Python 3.10/3.11 by flattening SelectableGroups via .select() instead of iterating .values().
Changes:
- Added a reference to issue #5231 in the module docstring.
- Updated
_as_entry_pointsto useeps.select()when available to avoid deprecated dict-like iteration.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+32
to
42
| # On Python 3.10 and 3.11, entry_points() returns a SelectableGroups | ||
| # object whose dict interface is deprecated and emits a DeprecationWarning | ||
| # when iterated via .values(). The correct way to flatten the groups is | ||
| # to call .select() without filters, which returns a flat EntryPoints list | ||
| # without triggering the deprecation warning. | ||
| # See: https://github.com/open-telemetry/opentelemetry-python/issues/5231 | ||
| if hasattr(eps, "select"): | ||
| return eps.select() | ||
| # Fallback for any other dict-like structure (should not be reached in | ||
| # practice but kept for robustness). | ||
| return EntryPoints(ep for group_eps in eps.values() for ep in group_eps) |
Contributor
|
This fix is not correct, and we also already have a PR open which fixes this properly. Closing this for now |
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.
Fixes #5231.
Problem
opentelemetry-apiv1.42.0 introduced_as_entry_points()in_importlib_metadata.py(via #5203) to normalise the return value ofimportlib.metadata.entry_points()across Python versions. On Python 3.10 and 3.11,entry_points()returns aSelectableGroupsobject whose dict interface is deprecated. The current implementation iterates it via.values(), which unconditionally emits:Projects that run CI with
-W error(warnings-as-errors) — which is common best practice — see this as an import-time error, breaking their test suites after upgrading from v1.41.1 to v1.42.0.Root cause
In
_as_entry_points():Fix
Prefer
.select()(called without filters) over.values(), which is the officially documented migration path for theSelectableGroupsdict interface. BothSelectableGroups(3.10/3.11) and the newerEntryPoints(3.12+) expose.select(), so ahasattrguard cleanly handles both cases without relying on isinstance checks against a private type:Testing