Skip to content

Fix Union entry point discovery on Python <3.12#84

Merged
NiklasRosenstein merged 6 commits into
developfrom
copilot/fix-importlib-metadata-usage
May 22, 2026
Merged

Fix Union entry point discovery on Python <3.12#84
NiklasRosenstein merged 6 commits into
developfrom
copilot/fix-importlib-metadata-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

databind.core.union.iter_entry_points() called importlib.metadata.entry_points(group=...), which is not supported on older Python versions (e.g. 3.9/3.11), causing runtime failures when resolving EntrypointUnionMembers. This change restores cross-version compatibility without raising the minimum supported Python version.

  • Entry point compatibility fix

    • Updated iter_entry_points(group) to call entry_points() without arguments.
    • Uses modern API when available: entry_points().select(group=...).
    • Falls back to legacy mapping-style return values via entry_points().get(group, ()).
  • Regression coverage

    • Added focused tests for both importlib metadata behaviors:
      • selectable EntryPoints object (.select(group=...))
      • mapping-style result ({group: [...]})
def iter_entry_points(group: str) -> t.Iterator[EntryPoint]:
    eps = entry_points()
    if hasattr(eps, "select"):
        return iter(eps.select(group=group))
    return iter(eps.get(group, ()))

Copilot AI changed the title [WIP] Fix importlib.metadata.entry_points usage for Python compatibility Fix Union entry point discovery on Python <3.12 May 20, 2026
Copilot AI requested a review from NiklasRosenstein May 20, 2026 22:24
claude added 3 commits May 22, 2026 07:48
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
@NiklasRosenstein NiklasRosenstein marked this pull request as ready for review May 22, 2026 16:53
@NiklasRosenstein NiklasRosenstein requested a review from Copilot May 22, 2026 16:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 call entry_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 setuptools runtime dependency (and types-setuptools dev dependency) since pkg_resources is 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.

Comment thread databind/src/databind/core/tests/union_test.py
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
@NiklasRosenstein NiklasRosenstein merged commit 2ff4805 into develop May 22, 2026
13 checks passed
@NiklasRosenstein NiklasRosenstein deleted the copilot/fix-importlib-metadata-usage branch May 22, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does not work under Python 3.9 (likely any version <3.12) because of wrong usage of importlib.metadata.entry_points

4 participants