Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly restore data for container #126

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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