fix(markers): normalize extras/dependency_groups membership values at parse time#1310
Open
r266-tech wants to merge 1 commit into
Open
fix(markers): normalize extras/dependency_groups membership values at parse time#1310r266-tech wants to merge 1 commit into
r266-tech wants to merge 1 commit into
Conversation
… parse time _normalize_extras (run in Marker.__init__) canonicalized only the singular 'extra == "X"' form. The plural set-valued membership forms '"X" in extras' and '"X" in dependency_groups' were left un-normalized at parse time, so __str__/__eq__/__hash__ disagreed with evaluate() (whose _normalize canonicalizes both operands for these keys) and with PEP 685 (extras) / PEP 735 (dependency groups), which mandate PEP 503 normalization. Extend the parse-time normalizer to canonicalize the membership literal, mirroring the existing extra guards, and add regression tests for str/eq/hash consistency (both 'in' and 'not in').
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.
Problem
_normalize_extras(the parse-time normalizer run inMarker.__init__/Requirement.__init__) canonicalizes only the singularextra == "X"form. The plural, set-valued membership forms"X" in extrasand"X" in dependency_groupsare left un-normalized at parse time, so a marker's__str__/__eq__/__hash__disagree with itsevaluate()result — and with PEP 685 (extras) / PEP 735 (dependency-groups), which mandate PEP 503 normalization of these names.evaluate()is consistent because_normalizecanonicalizes both operands wheneverkey in MARKERS_ALLOWING_SET; only the parse-time path was missing the plural case. The practical consequence is that equal extras/dependency-groups markers fail to dedup in sets/dicts and compare unequal in requirement/lock-file processing.Fix
Extend
_normalize_extrasto canonicalize the string-literal operand when the other operand is aVariablenamedextras/dependency_groups, mirroring the existingextraguards. The membership variable is always the right-hand operand (Value in Variable), so a single branch covers bothinandnot in. No operator check is needed because_normalizealready normalizes these keys regardless of operator, so parse-time and eval-time now agree.This is a follow-up completing the plural-membership gap left by the recent PEP 685 normalization work (#1246 nested singular
extra, #1278Requirementextras).Tests
Added
test_membership_value_str_normalizationand..._negated(parametrized overextras/dependency_groups) assertingstr,==, andhashconsistency for bothinandnot in. Fulltests/test_markers.py(2284 tests) passes;ruff checkandruff formatare clean.