fix(markers): correct Marker.evaluate :raises: from docs (and subclass KeyError for backcompat) - #1276
Conversation
|
We could make |
…r missing env keys Per @henryiii's review on pypa#1239: make UndefinedEnvironmentName a KeyError subclass (was ValueError) and actually raise it from Marker.evaluate(), so the exported exception becomes meaningful and the documented :raises: is true again. Missing environment keys previously surfaced as a bare KeyError straight from the dict lookup in _evaluate_markers; tests pinned that KeyError. Because UndefinedEnvironmentName now subclasses KeyError, that contract is preserved (existing 'with pytest.raises(KeyError)' assertions still pass and external 'except KeyError' keeps working) while callers can catch the specific type. refs pypa#1239
0cfa0aa to
05b6ea5
Compare
|
Done — force-pushed the branch to exactly that. Since it's a |
Resolves the
Marker.evaluateitem from your review checklist in #1239:UndefinedEnvironmentNameis exported inmarkers.py__all__and defined as a class, but it is never raised anywhere in the source.evaluate()readsenvironment[environment_key]directly (markers.py:273/:278), so a missing environment key surfaces as a bareKeyError, and the tests pin exactly that (tests/test_markers.py:505/:508). The docstring has been wrong since the exception became dead.This PR takes the low-risk, behavior-preserving fork of your decide:
evaluate()docstring:raises:fromUndefinedEnvironmentNametoKeyError(matches the test-pinned behavior), andUndefinedEnvironmentNameimport from thedocs/markers.rstdoctest (it is never referenced again, so the doctest still runs).I deliberately kept the
__all__export and the class definition, and did not changeevaluate()to actually raiseUndefinedEnvironmentName— both of those would be behavior / public-API changes. If you'd rather go the other way (makeevaluate()raiseUndefinedEnvironmentNameso the exported class becomes meaningful and the original docstring becomes true), I'm happy to send that version instead — just say the word.The sibling
:raises UndefinedComparison:is genuinely raised (markers.py:234) and is left untouched.