diff --git a/README.md b/README.md index 3db4ffb..674f4ab 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/tomli/_parser.py b/src/tomli/_parser.py index 65da389..614e729 100644 --- a/src/tomli/_parser.py +++ b/src/tomli/_parser.py @@ -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] = [{}]