From 682e71fccf5ccc8f4cf7d48565a558b2d489433f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 2 Nov 2026 18:39:53 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(py=5Finfo):=20preserve=20sup?= =?UTF-8?q?plied=20JSON=20keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/changelog/+property-keys.bugfix.rst | 1 + src/python_discovery/_py_info.py | 2 +- tests/py_info/test_py_info.py | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/+property-keys.bugfix.rst diff --git a/docs/changelog/+property-keys.bugfix.rst b/docs/changelog/+property-keys.bugfix.rst new file mode 100644 index 0000000..8a5526b --- /dev/null +++ b/docs/changelog/+property-keys.bugfix.rst @@ -0,0 +1 @@ +Preserve interpreter-provided values when answer keys match computed properties during cache serialization. diff --git a/src/python_discovery/_py_info.py b/src/python_discovery/_py_info.py index ecf6cc6..5bc1e26 100644 --- a/src/python_discovery/_py_info.py +++ b/src/python_discovery/_py_info.py @@ -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 diff --git a/tests/py_info/test_py_info.py b/tests/py_info/test_py_info.py index 9b0b802..852d925 100644 --- a/tests/py_info/test_py_info.py +++ b/tests/py_info/test_py_info.py @@ -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)