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

fix: unwrap() for container children values #266

Merged
merged 1 commit into from
Jan 29, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]


### Fixed

- Parse empty table name if it is quoted. ([#258](https://github.com/sdispater/tomlkit/issues/258))
- 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))

## [0.11.6] - 2022-10-27

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def unwrap(self) -> Dict[str, Any]:
if isinstance(k, Key):
k = k.key

if isinstance(v, Item):
if hasattr(v, "unwrap"):
v = v.unwrap()

if k in unwrapped:
Expand Down
11 changes: 7 additions & 4 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def _group_values(self, value: List[Item]) -> List[_ArrayItemGroup]:
def unwrap(self) -> List[Any]:
unwrapped = []
for v in self:
if isinstance(v, Item):
if hasattr(v, "unwrap"):
unwrapped.append(v.unwrap())
else:
unwrapped.append(v)
Expand Down Expand Up @@ -1317,7 +1317,10 @@ def __len__(self) -> int:
return list.__len__(self)

def __getitem__(self, key: Union[int, slice]) -> Any:
return list.__getitem__(self, key)
rv = cast(Item, list.__getitem__(self, key))
if rv.is_boolean():
return bool(rv)
return rv

def __setitem__(self, key: Union[int, slice], value: Any) -> Any:
it = item(value, _parent=self)
Expand Down Expand Up @@ -1438,7 +1441,7 @@ def unwrap(self) -> Dict[str, Any]:
for k, v in self.items():
if isinstance(k, Key):
k = k.key
if isinstance(v, Item):
if hasattr(v, "unwrap"):
v = v.unwrap()
unwrapped[k] = v

Expand Down Expand Up @@ -1835,7 +1838,7 @@ def __init__(
def unwrap(self) -> List[Dict[str, Any]]:
unwrapped = []
for t in self._body:
if isinstance(t, Item):
if hasattr(t, "unwrap"):
unwrapped.append(t.unwrap())
else:
unwrapped.append(t)
Expand Down