Skip to content

Commit

Permalink
fix: unwrap() for container children values (python-poetry#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored and capuanob committed Jan 31, 2023
1 parent e9c1187 commit ff07013
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit ff07013

Please sign in to comment.