Skip to content

Commit

Permalink
Allow parse_float to return values with append attr
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Feb 2, 2022
1 parent ecc36aa commit 0eaf93d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ assert toml_dict["precision-matters"] == Decimal("0.982492")
Note that `decimal.Decimal` can be replaced with another callable that converts a TOML float from string to a Python type.
The `decimal.Decimal` is, however, a practical choice for use cases where float inaccuracies can not be tolerated.

Illegal types include `dict`, `list`, and anything that has the `append` attribute.
Illegal types are `dict` and `list`, and their subtypes.
Parsing floats into an illegal type results in undefined behavior.

## FAQ<a name="faq"></a>
Expand Down
5 changes: 2 additions & 3 deletions src/tomli/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ def append_nest_to_list(self, key: Key) -> None:
last_key = key[-1]
if last_key in cont:
list_ = cont[last_key]
try:
list_.append({})
except AttributeError:
if not isinstance(list_, list):
raise KeyError("An object other than list found behind this key")
list_.append({})
else:
cont[last_key] = [{}]

Expand Down

0 comments on commit 0eaf93d

Please sign in to comment.