Fix Union entry point discovery on Python <3.12#84
Merged
Conversation
Agent-Logs-Url: https://github.com/NiklasRosenstein/python-databind/sessions/7bb05856-0ab9-441a-8997-2e48bf9ff284 Co-authored-by: NiklasRosenstein <1318438+NiklasRosenstein@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix importlib.metadata.entry_points usage for Python compatibility
Fix May 20, 2026
Union entry point discovery on Python <3.12
The new union_test.py used PEP 604 (`str | None`) annotations that fail to evaluate on Python 3.9, and exercised the importlib.metadata-backed `iter_entry_points` which only exists on Python >= 3.9 (3.8 uses the pkg_resources path, so `monkeypatch.setattr` had no `entry_points` attribute to patch). Defer annotation evaluation via `from __future__ import annotations` and skip the module on Python < 3.9. Also add the missing changelog entry required by the Changelog CI check. https://claude.ai/code/session_01VxEPWDAPMXVUE4XhbDjNFT
…adata importlib.metadata has been available since Python 3.8, and the new entry_points() + .select/.get handling works across all supported versions, so the version-gated pkg_resources branch is no longer needed. This removes a dependency on the deprecated pkg_resources and lets the union entry point tests run on every Python version without a skip. https://claude.ai/code/session_01VxEPWDAPMXVUE4XhbDjNFT
With the pkg_resources fallback in union.py gone, the runtime setuptools dependency (declared only for Python <3.9 to provide pkg_resources) and the types-setuptools mypy stub are no longer used. https://claude.ai/code/session_01VxEPWDAPMXVUE4XhbDjNFT
There was a problem hiding this comment.
Pull request overview
Fixes databind.core.union.iter_entry_points() to work across supported Python versions by avoiding the unsupported entry_points(group=...) call on Python < 3.12, while also removing the now-unneeded pkg_resources/setuptools fallback path.
Changes:
- Update
iter_entry_points(group)to callentry_points()without arguments and select the group via.select()when available, otherwise fall back to mapping-style results. - Add regression tests covering both “selectable” and “mapping-style”
entry_points()return shapes. - Drop the
setuptoolsruntime dependency (andtypes-setuptoolsdev dependency) sincepkg_resourcesis no longer used.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
databind/src/databind/core/union.py |
Reworks entry point enumeration to be compatible with older importlib.metadata APIs. |
databind/src/databind/core/tests/union_test.py |
Adds regression tests for both entry_points().select() and mapping-style entry_points() behaviors. |
databind/pyproject.toml |
Removes conditional runtime dependency on setuptools for Python < 3.9. |
pyproject.toml |
Removes types-setuptools from the workspace dev dependency group. |
uv.lock |
Reflects dependency removals (setuptools, types-setuptools) in the lockfile. |
.changelog/_unreleased.toml |
Adds an unreleased changelog entry describing the fix and dependency removal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use the public `pytest.MonkeyPatch` entrypoint instead of the private `_pytest.monkeypatch` module, which is not part of pytest's public API. https://claude.ai/code/session_01VxEPWDAPMXVUE4XhbDjNFT
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.
databind.core.union.iter_entry_points()calledimportlib.metadata.entry_points(group=...), which is not supported on older Python versions (e.g. 3.9/3.11), causing runtime failures when resolvingEntrypointUnionMembers. This change restores cross-version compatibility without raising the minimum supported Python version.Entry point compatibility fix
iter_entry_points(group)to callentry_points()without arguments.entry_points().select(group=...).entry_points().get(group, ()).Regression coverage
EntryPointsobject (.select(group=...)){group: [...]})