Skip to content

Commit

Permalink
Fix out of order tables dict-like behavior (python-poetry#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored Feb 28, 2020
1 parent 80d3792 commit 15a231f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,21 @@ def test_values_can_still_be_set_for_out_of_order_tables():

with pytest.raises(NonExistentKey):
del doc["a"]["a"]["key"]


def test_out_of_order_tables_are_still_dicts():
content = """
[a.a]
key = "value"
[a.b]
[a.a.c]
"""

doc = parse(content)
assert isinstance(doc["a"], dict)
assert isinstance(doc["a"]["a"], dict)

assert "key" in doc["a"]["a"]
assert "c" in doc["a"]["a"]
11 changes: 10 additions & 1 deletion tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def __copy__(self): # type: () -> Container
return c


class OutOfOrderTableProxy(object):
class OutOfOrderTableProxy(dict):
def __init__(self, container, indices): # type: (Container, Tuple) -> None
self._container = container
self._internal_container = Container(self._container.parsing)
Expand Down Expand Up @@ -692,6 +692,15 @@ def __delitem__(self, key): # type: (Union[Key, str]) -> None

del self._internal_container[key]

def keys(self):
return self._internal_container.keys()

def values(self):
return self._internal_container.values()

def __contains__(self, key):
return key in self._internal_container

def __str__(self):
return str(self._internal_container)

Expand Down

0 comments on commit 15a231f

Please sign in to comment.