Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/+property-keys.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve interpreter-provided values when answer keys match computed properties during cache serialization.
2 changes: 1 addition & 1 deletion src/python_discovery/_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def to_json(self) -> str:

def to_dict(self) -> dict[str, InfoValue]:
"""Convert this interpreter information to a plain dictionary."""
data = {var: (getattr(self, var) if var != "_creators" else None) for var in vars(self)}
data = {name: None if name == "_creators" else value for name, value in vars(self).items()}
version_info = data["version_info"]
data["version_info"] = version_info._asdict() if hasattr(version_info, "_asdict") else version_info
return data
Expand Down
6 changes: 6 additions & 0 deletions tests/py_info/test_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ def test_py_info_to_dict_includes_sysconfig_platform() -> None:
assert data["sysconfig_platform"] == sysconfig.get_platform()


def test_py_info_to_dict_preserves_property_named_answer_key() -> None:
data = CURRENT.to_dict()
data["system_include"] = "supplied path"
assert PythonInfo.from_dict(data).to_dict()["system_include"] == "supplied path"


def test_py_info_json_round_trip() -> None:
json_str = CURRENT.to_json()
parsed = json.loads(json_str)
Expand Down