fix: make Requirements/Markers pickle-safe#1171
Conversation
|
Needs #1168, since Specifiers are contained inside. |
2824080 to
6cd4665
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds pickle stability/backwards-compatibility support for Requirement, Marker, and marker parser Node objects (similar to prior Specifier/Version work), along with tests that ensure both new and legacy pickle formats round-trip correctly.
Changes:
- Implement
__getstate__/__setstate__forRequirement,Marker, and_parser.Nodeto support compact, stable pickling plus legacy state formats. - Add pytest coverage for pickle round-trips and loading pickles generated by older
packagingversions. - Update
typosconfiguration to silence false positives from embedded pickle byte streams.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/packaging/requirements.py |
Pickle state now serializes as a requirement string; legacy __dict__ restore supported. |
src/packaging/markers.py |
Pickle state now serializes as a marker expression string; legacy dict/slots restore supported. |
src/packaging/_parser.py |
Adds pickle support for marker AST node types via string state + legacy restore. |
tests/test_requirements.py |
Adds round-trip + legacy pickle fixture tests for Requirement. |
tests/test_markers.py |
Adds round-trip + legacy pickle fixture tests for Marker and Node types. |
pyproject.toml |
Extends typos allowlist to accommodate pickle-byte literals in tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self._restore_value(slot_dict["value"]) | ||
| return | ||
| if isinstance(state, dict) and "value" in state: | ||
| # Old format (packaging <= 26.0, no __slots__): plain __dict__. |
There was a problem hiding this comment.
I think this should be < 26.0, slots were added in 26.0, right?
There was a problem hiding this comment.
No, Marker is the only one we missed and added in 26.1. (#1147)
There was a problem hiding this comment.
Oh, I see, this is Node, not Marker, sorry. Yes, I think you are right (#1032).
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Assisted-by: OpenCode:Qwen3.6-27B Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Assisted-by: Copilot:Kimi-K2.6 Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
06f9df6 to
b880d50
Compare
Similar to #1168, but for Requirements/Markers.
🤖 Using Copilot (auto model)