Skip to content

Defer EntryPoint value validation until loading - #547

Merged
jaraco merged 2 commits into
python:mainfrom
rudra337-lgtm:fix/523-defer-entry-point-validation
Oct 21, 2026
Merged

jaraco merged 2 commits into
python:mainfrom
rudra337-lgtm:fix/523-defer-entry-point-validation

Conversation

@rudra337-lgtm

Copy link
Copy Markdown
Contributor

Fixes #523.

EntryPoint.__init__ previously parsed and validated value immediately. Since entry_points(group=...) constructs entries before applying the group filter, one malformed entry in an unrelated group could prevent callers from retrieving valid entries. Defer parsing until a component is accessed or load() is called; malformed entries still raise ValueError when used.

The regression test creates a distribution with a valid selected group and an invalid unselected group, verifies selection succeeds, and verifies loading the invalid entry still raises ValueError.

Validation:

  • tests/test_api.py: 38 passed, 39 subtests passed.
  • Existing TestEntryPoints unit tests: 8 passed.
  • Ruff and git diff --check passed.

AI assistance was used to prepare and validate this change; the reported checks were run locally.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread importlib_metadata/__init__.py Outdated
or loaded.

>>> EntryPoint(name=None, group=None, value='invalid-name')
>>> EntryPoint(name=None, group=None, value='invalid-name').load()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The distinctive difference here is that it does not fail prior to loading, so I'd change this example to capture that expectation. i.e. "raises only when accessed or loaded" and then in the example, construct one to a variable and then have the exception raise on load.

Suggested change
>>> EntryPoint(name=None, group=None, value='invalid-name').load()
>>> ep = EntryPoint(name=None, group=None, value='invalid-name')
>>> ep.load()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Done in 7d96b5a — the example now constructs ep and raises on ep.load(), with the prose reading "Construction never raises; the value is validated only when accessed or loaded."

Also in that commit: dropped the redundant textwrap.dedent from the new test (tests/fixtures.py already dedents and left-strips all string file contents), normalized the fixture dist-info name, and matched the assertion style of the neighboring tests.

The distinctive behavior is that construction no longer fails, so
demonstrate that by constructing an invalid EntryPoint and only then
raising on load. In the test, rely on the fixtures' dedenting of file
contents and match the style of the neighboring tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jaraco
jaraco merged commit 0e2b999 into python:main Oct 21, 2026
15 of 16 checks passed
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.

Using entry-point value for non-object references

2 participants