Skip to content

Commit 7134436

Browse files
authored
fix: unwrap() for container children values (#266)
1 parent b49a3e4 commit 7134436

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## [Unreleased]
44

5+
6+
### Fixed
7+
8+
- Parse empty table name if it is quoted. ([#258](https://github.com/sdispater/tomlkit/issues/258))
9+
- Fix the `unwrap()` method for `Container` children values which sometimes returns an internal object if the table is an out-of-order table. ([#264](https://github.com/sdispater/tomlkit/issues/264))
10+
511
## [0.11.6] - 2022-10-27
612

713
### Fixed

tomlkit/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def unwrap(self) -> Dict[str, Any]:
5555
if isinstance(k, Key):
5656
k = k.key
5757

58-
if isinstance(v, Item):
58+
if hasattr(v, "unwrap"):
5959
v = v.unwrap()
6060

6161
if k in unwrapped:

tomlkit/items.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ def _group_values(self, value: List[Item]) -> List[_ArrayItemGroup]:
11661166
def unwrap(self) -> List[Any]:
11671167
unwrapped = []
11681168
for v in self:
1169-
if isinstance(v, Item):
1169+
if hasattr(v, "unwrap"):
11701170
unwrapped.append(v.unwrap())
11711171
else:
11721172
unwrapped.append(v)
@@ -1317,7 +1317,10 @@ def __len__(self) -> int:
13171317
return list.__len__(self)
13181318

13191319
def __getitem__(self, key: Union[int, slice]) -> Any:
1320-
return list.__getitem__(self, key)
1320+
rv = cast(Item, list.__getitem__(self, key))
1321+
if rv.is_boolean():
1322+
return bool(rv)
1323+
return rv
13211324

13221325
def __setitem__(self, key: Union[int, slice], value: Any) -> Any:
13231326
it = item(value, _parent=self)
@@ -1438,7 +1441,7 @@ def unwrap(self) -> Dict[str, Any]:
14381441
for k, v in self.items():
14391442
if isinstance(k, Key):
14401443
k = k.key
1441-
if isinstance(v, Item):
1444+
if hasattr(v, "unwrap"):
14421445
v = v.unwrap()
14431446
unwrapped[k] = v
14441447

@@ -1835,7 +1838,7 @@ def __init__(
18351838
def unwrap(self) -> List[Dict[str, Any]]:
18361839
unwrapped = []
18371840
for t in self._body:
1838-
if isinstance(t, Item):
1841+
if hasattr(t, "unwrap"):
18391842
unwrapped.append(t.unwrap())
18401843
else:
18411844
unwrapped.append(t)

0 commit comments

Comments
 (0)