Skip to content

Add raw version input accessor - #1419

Open
r266-tech wants to merge 1 commit into
pypa:mainfrom
r266-tech:codex/version-raw-version
Open

r266-tech wants to merge 1 commit into
pypa:mainfrom
r266-tech:codex/version-raw-version

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

Add a read-only Version.raw_version property that preserves the exact input string used by the constructor. Versions built with from_parts, changed with __replace__, or restored from older pickles return None; unchanged replacements preserve the original value. Comparison and hashing remain based only on normalized PEP 440 fields.

New pickles include the raw input, while __setstate__ continues to accept the existing six-field and older pickle formats.

Fixes #1418.

Validation

  • uv run --no-sync pytest -q tests/test_version.py — 51,525 passed.
  • ruff check src/packaging/version.py tests/test_version.py — passed.
  • ruff format --check src/packaging/version.py tests/test_version.py — passed.
  • git diff --check — passed.

@r266-tech
r266-tech force-pushed the codex/version-raw-version branch from 0113517 to cab6070 Compare October 9, 2026 10:18

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raw accessor retains the exact input spelling, including whitespace, leading v, capitalization and local-version text. Pickle protocols 2–5 preserve that string without changing equality/hash; versions built from parts, replaced versions and legacy six-field states return None for raw input.

Checked cab6070464d8 with standalone Python 3.12.14 checks (49 passing assertions). I haven't run the full upstream suite.

This branch has not been deployed

No deployments
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.

Preserved original string for Version

2 participants