Skip to content

Commit cc05afa

Browse files
authored
Represent out-of-order table proxies with merged values (#536)
1 parent 76bb47a commit cc05afa

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎tests/test_toml_document.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,17 @@ def test_repr() -> None:
887887
assert repr(doc["namespace"]) == "{'key1': 'value1', 'key2': 'value2'}"
888888

889889

890+
def test_repr_out_of_order_table_proxy() -> None:
891+
doc = parse("""\
892+
a.b.c = "d"
893+
a.b.e = "f"
894+
""")
895+
expected = "{'b': {'c': 'd', 'e': 'f'}}"
896+
897+
assert repr(doc["a"]) == expected
898+
assert str(doc["a"]) == expected
899+
900+
890901
def test_deepcopy() -> None:
891902
content = """
892903
[tool]

‎tomlkit/container.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,12 @@ def unwrap(self) -> dict[str, Any]:
11231123
def value(self) -> dict[str, Any]:
11241124
return self._internal_container.value
11251125

1126+
def __str__(self) -> str:
1127+
return str(self.value)
1128+
1129+
def __repr__(self) -> str:
1130+
return repr(self.value)
1131+
11261132
def __contains__(self, key: object) -> bool:
11271133
# Native membership test. The inherited ``MutableMapping.__contains__``
11281134
# resolves the value via ``__getitem__`` (and builds a ``NonExistentKey``

0 commit comments

Comments
 (0)