-
Notifications
You must be signed in to change notification settings - Fork 191
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
mixed types in array don't work #270
Comments
This was only recently added to toml itself: toml-lang/toml#676 Edit: Wait, I think 2 different issues are going on here. The first is that indeed
is parsed to
throws the Finally,
i.e., without the trailing comma, raises |
I can still reproduce this error and, indeed, the result is rather inconsisten: it can dump arrays with mixed types, but it fails when loading that same output. To reproduce:
import toml
data = {"a": [1, "cat"]}
data_encoded = toml.dumps(data) The above works and results in data_back = toml.loads(data_encoded) results in:
The same applies when loading/dumping to a file rather than a string. |
Reproduced this error with mixed integer/float array Python: 3.7.5 Dumpimport toml
mixed_types = [0, 1.1, 2.2, 3.3] # mixed integer and floats
toml.dumps({'array': mixed_types})
Loadtoml.loads(toml.dumps({'array': mixed_types}))
Spec v1.0.0-rc.2 says:
# Mixed-type arrays are allowed
numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
contributors = [
"Foo Bar <[email protected]>",
{ name = "Baz Qux", email = "[email protected]", url = "https://example.com/bazqux" }
] |
Still a problem on Python 3.9.9 with toml 0.10.2:
Error:
Doc (https://toml.io/en/v1.0.0#array):
|
Still a problem 3 years later... See python-poetry/poetry#7094 |
- Switch from "toml" to "tomlib + tomli-w" - Fixes an issue reading mixed types lists uiri/toml#270 (and empty sets writing `[false,]` but that has no open issues) - Use StrEnum to simplify `CaptureMethodEnum`
- Switch from "toml" to "tomlib + tomli-w" - Fixes an issue reading mixed types lists uiri/toml#270 (and empty sets writing `[false,]` but that has no open issues) - Use StrEnum to simplify `CaptureMethodEnum`
Yup like cykerway said, this should be allowed: https://toml.io/en/v1.0.0#array:~:text=%23%20Mixed%2Dtype%20arrays%20are%20allowed%0Anumbers%20%3D%20%5B%200.1%2C%200.2%2C%200.5%2C%201%2C%202%2C%205%20%5D Still a problem 5 years later. EDIT: Actually, this has been fixed in the master branch: 6d51c0a But no new version of the package has been released since 2020. And the maintainer seems dead. Maybe @arp242, who made the commit, knows anything about the pypi status? |
this way file will be parsed but
"foo"
will be ignored:{config: {list: [{key: value}]}}
After parsing toml file above parser will throw an error:
IndexError: list index out of range
.Traceback:
The text was updated successfully, but these errors were encountered: