Skip to content

Avoid SelectableGroups deprecation warning#5238

Open
HasanTasdiq wants to merge 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-importlib-metadata-selectablegroups-warning
Open

Avoid SelectableGroups deprecation warning#5238
HasanTasdiq wants to merge 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-importlib-metadata-selectablegroups-warning

Conversation

@HasanTasdiq
Copy link
Copy Markdown
Contributor

@HasanTasdiq HasanTasdiq commented May 20, 2026

Fixes #5231

Summary

  • Updated the importlib metadata compatibility wrapper to normalize SelectableGroups without using its deprecated dict interface.
  • Added regression coverage that treats DeprecationWarning as an error while converting SelectableGroups.
  • Added the towncrier changelog fragment for this API compatibility fix.

Why

On Python 3.10 and 3.11, importlib.metadata.entry_points() can return SelectableGroups. Calling its dict-like values() emits a DeprecationWarning, which breaks users running with warnings as errors when importing opentelemetry.context.

Testing

  • Ran: python3 -m pytest opentelemetry-api/tests/util/test__importlib_metadata.py - passed
  • Ran: python3 -W error -c 'import opentelemetry.context' - passed\n- Ran: python3 -W error -m pytest opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n- Ran: python3 -m ruff check opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n- Ran: python3 -m py_compile opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n\n## Notes\n- Full tox/precommit not run locally because uv and tox are not installed in this shell.\n

@HasanTasdiq HasanTasdiq marked this pull request as ready for review May 20, 2026 23:05
@HasanTasdiq HasanTasdiq requested a review from a team as a code owner May 20, 2026 23:05
def _as_entry_points(eps: Any) -> EntryPoints:
if isinstance(eps, EntryPoints):
return eps
if hasattr(eps, "groups") and hasattr(eps, "select"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't really need this conditional branch here at all, we can probably just replace the last lines of this function directly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might just be better to just keep the old pattern and suppress the warnings - the reason being that this new implementation needs to iterate through all entry points for every group (because "select" has to search all entry points), whereas the prior approach is still a single pass

@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Importing opentelemetry.context issues a warning in Python 3.10 and 3.11

3 participants