Repository navigation
Defer EntryPoint value validation until loading - #547
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| or loaded. | ||
|
|
||
| >>> EntryPoint(name=None, group=None, value='invalid-name') | ||
| >>> EntryPoint(name=None, group=None, value='invalid-name').load() |
There was a problem hiding this comment.
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.
| >>> EntryPoint(name=None, group=None, value='invalid-name').load() | |
| >>> ep = EntryPoint(name=None, group=None, value='invalid-name') | |
| >>> ep.load() |
There was a problem hiding this comment.
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>
Fixes #523.
EntryPoint.__init__previously parsed and validatedvalueimmediately. Sinceentry_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 orload()is called; malformed entries still raiseValueErrorwhen 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.TestEntryPointsunit tests: 8 passed.git diff --checkpassed.AI assistance was used to prepare and validate this change; the reported checks were run locally.