diff --git a/tests/test_toml_document.py b/tests/test_toml_document.py index 1cdfb9c..06291e3 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 75e0901..a9f29a9 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``