Skip to content

Commit 0eaf93d

Browse files
committed
Allow parse_float to return values with append attr
1 parent ecc36aa commit 0eaf93d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ assert toml_dict["precision-matters"] == Decimal("0.982492")
9595
Note that `decimal.Decimal` can be replaced with another callable that converts a TOML float from string to a Python type.
9696
The `decimal.Decimal` is, however, a practical choice for use cases where float inaccuracies can not be tolerated.
9797

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

101101
## FAQ<a name="faq"></a>

src/tomli/_parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ def append_nest_to_list(self, key: Key) -> None:
216216
last_key = key[-1]
217217
if last_key in cont:
218218
list_ = cont[last_key]
219-
try:
220-
list_.append({})
221-
except AttributeError:
219+
if not isinstance(list_, list):
222220
raise KeyError("An object other than list found behind this key")
221+
list_.append({})
223222
else:
224223
cont[last_key] = [{}]
225224

0 commit comments

Comments
 (0)