fix(markers): handle version pattern on LHS when marker variable is on RHS#1172
Open
armorbreak001 wants to merge 1 commit intopypa:mainfrom
Open
fix(markers): handle version pattern on LHS when marker variable is on RHS#1172armorbreak001 wants to merge 1 commit intopypa:mainfrom
armorbreak001 wants to merge 1 commit intopypa:mainfrom
Conversation
…n RHS
When a marker like "'3.12.*' == python_full_version" is evaluated,
the variable is on the RHS so the resolved env value (e.g. '3.12.3')
was used as the specifier pattern while the literal ('3.12.*') was
treated as the item to check. Since '3.12.*' is not a valid PEP 440
version, Specifier.contains() silently returned False.
Now try building the specifier from lhs when the first attempt doesn't
match and lhs doesn't parse as a concrete version.
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.
Summary
Fixes #934
When a marker expression has the version pattern (e.g.
'3.12.*') on the left-hand side and the variable (e.g.python_full_version) on the right-hand side, evaluation produced incorrect results.For example,
"'3.12.*' == python_full_version"evaluated toFalseeven when the Python version was 3.12.3, because the resolved env value ('3.12.3') was used as the specifier pattern while the literal ('3.12.*') — which is not a valid PEP 440 version — was passed toSpecifier.contains(), which silently returnedFalse.Details
The fix in
_eval_op(): after the normalspec.contains(lhs)attempt doesn't match, check whetherlhslooks like a version pattern rather than a concrete version (by checking if it can be parsed as aVersion). If it can't, try building the specifier fromlhsinstead and checkingrhsagainst it.The guard using
Version(lhs)ensures we don't accidentally flip the meaning of asymmetric operators like</>where both sides are concrete versions — only actual version patterns (wildcards, pre-release tags used as patterns, etc.) trigger the fallback.Testing
All existing tests pass (2262/2262). Verified with the exact case from the issue:
"'3.12.*' == python_full_version"→True(wasFalse)