Skip to content

fix: normalize nested extra marker values - #1246

Merged
henryiii merged 2 commits into
pypa:mainfrom
r266-tech:fix-nested-extra-marker-normalization
Jun 16, 2026
Merged

henryiii merged 2 commits into
pypa:mainfrom
r266-tech:fix-nested-extra-marker-normalization

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Fixes one of the markers.py issues reported in #1239.

_normalize_extra_values() delegates each top-level marker item to _normalize_extras(), but _normalize_extras() only handled tuples. Parenthesized marker groups are represented as nested lists, so literal extra comparisons inside parentheses skipped PEP 685 normalization.

This makes _normalize_extras() recurse through nested marker lists and keeps the literal-only guards around extra normalization so variable operands are not rewritten by this scoped fix.

Tests:

  • uv run pytest tests/test_markers.py -q
  • uv run ruff check src/packaging/markers.py tests/test_markers.py
  • uv run ruff format --check src/packaging/markers.py tests/test_markers.py

Pre-submit review: Codex approved the final scoped diff after earlier review feedback identified that broader variable-variable marker semantics should be left for a separate, spec-backed patch.

Comment thread src/packaging/markers.py Resolved

@notatallshaw notatallshaw left a comment

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 isinstance(rhs, Value) / isinstance(lhs, Value) guards also fix a separate bug: a variable-vs-variable atom no longer gets rewritten into a string literal:

  str(Marker("extra == os_name"))   # main:  extra == "os-name"   (os_name turned into a literal!)
                                     # here:  extra == os_name     (correct)

Add a test for this.

Add a regression test for the case where extra is compared to another
environment variable rather than a string literal. The isinstance guards
ensure such atoms are left untouched instead of being rewritten into a
normalized string literal.

Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii henryiii changed the title Normalize nested extra marker values fix: normalize nested extra marker values Jun 16, 2026
@henryiii
henryiii merged commit 0726512 into pypa:main Jun 16, 2026
69 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.

3 participants