From 9380fcd5a935cd4a1408cabbb9ef56ab032f8a3e Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Mon, 22 Jun 2026 11:23:04 +0200 Subject: [PATCH] Represent out-of-order table proxies with merged values --- tests/test_toml_document.py | 11 +++++++++++ tomlkit/container.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/tests/test_toml_document.py b/tests/test_toml_document.py index 1cdfb9c5..06291e36 100644 --- a/tests/test_toml_document.py +++ b/tests/test_toml_document.py @@ -846,6 +846,17 @@ def test_repr() -> None: assert repr(doc["namespace"]) == "{'key1': 'value1', 'key2': 'value2'}" +def test_repr_out_of_order_table_proxy() -> None: + doc = parse("""\ +a.b.c = "d" +a.b.e = "f" +""") + expected = "{'b': {'c': 'd', 'e': 'f'}}" + + assert repr(doc["a"]) == expected + assert str(doc["a"]) == expected + + def test_deepcopy() -> None: content = """ [tool] diff --git a/tomlkit/container.py b/tomlkit/container.py index 75e09018..a9f29a9b 100644 --- a/tomlkit/container.py +++ b/tomlkit/container.py @@ -1057,6 +1057,12 @@ def unwrap(self) -> dict[str, Any]: def value(self) -> dict[str, Any]: return self._internal_container.value + def __str__(self) -> str: + return str(self.value) + + def __repr__(self) -> str: + return repr(self.value) + def __contains__(self, key: object) -> bool: # Native membership test. The inherited ``MutableMapping.__contains__`` # resolves the value via ``__getitem__`` (and builds a ``NonExistentKey``