Skip to content

Commit

Permalink
Merge pull request #126 from frostming/patch-1
Browse files Browse the repository at this point in the history
Correctly restore data for container
  • Loading branch information
sdispater committed May 20, 2021
2 parents 1b610fd + 4cdc2f6 commit 351d662
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tests/test_toml_document.py
Expand Up @@ -669,3 +669,16 @@ def test_repr():
)

assert repr(doc["namespace"]) == "{'key1': 'value1', 'key2': 'value2'}"


def test_deepcopy():
content = """
[tool]
name = "foo"
[tool.project.section]
option = "test"
"""
doc = parse(content)
copied = copy.deepcopy(doc)
assert copied == doc
assert copied.as_string() == content
7 changes: 6 additions & 1 deletion tomlkit/container.py
Expand Up @@ -654,13 +654,18 @@ def __reduce_ex__(self, protocol):
return (
self.__class__,
self._getstate(protocol),
(self._map, self._body, self._parsed),
(self._map, self._body, self._parsed, self._table_keys),
)

def __setstate__(self, state):
self._map = state[0]
self._body = state[1]
self._parsed = state[2]
self._table_keys = state[3]

for key, item in self._body:
if key is not None:
dict.__setitem__(self, key.key, item.value)

def copy(self): # type: () -> Container
return copy.copy(self)
Expand Down

0 comments on commit 351d662

Please sign in to comment.