Skip to content

Commit 8fc73fc

Browse files
Aot __setitem__ not implemented fix (#413)
* Fix AOT __setitem__ raising not implemented * Checking returned types after __setitems__ on AOT * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1a3085c commit 8fc73fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/test_items.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ def test_aot_unwrap():
129129
assert_is_ppo(vu, str)
130130

131131

132+
def test_aot_set_item():
133+
d = item(["A", {"b": "B"}, ["c", "D"]])
134+
d[0] = "C"
135+
assert isinstance(d[0], String)
136+
assert d[0] == "C"
137+
d[1]["b"] = "D"
138+
assert isinstance(d[1], InlineTable)
139+
assert d[1]["b"] == "D"
140+
d[0] = ["c", "C"]
141+
assert isinstance(d[0], Array)
142+
assert d[0][1] == "C"
143+
144+
132145
def test_time_unwrap():
133146
t = time(3, 8, 14)
134147
elementary_test(item(t), time)

tomlkit/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ def __getitem__(self, key):
18851885
return self._body[key]
18861886

18871887
def __setitem__(self, key: slice | int, value: Any) -> None:
1888-
raise NotImplementedError
1888+
self._body[key] = item(value, _parent=self)
18891889

18901890
def __delitem__(self, key: slice | int) -> None:
18911891
del self._body[key]

0 commit comments

Comments
 (0)