jupyter / papyri

MIT License
84 stars 17 forks source link

Use tomllib/tomli instead of toml #269

Closed asmeurer closed 1 year ago

asmeurer commented 1 year ago

toml has a strange bug where its dumps() turns strings into arrays, leading to things like

NumpydocParseError = [ [ "n",
"u",
"m",
"p",
"y",
".",
"p",
"o",
"l",
"y",
"n",
"o",
"m",
"i",
"a",
"l",
".",
"_",
"p",
"o",
"l",
"y",
"b",
"a",
"s",
"e",
":",
"A",
"B",
"C",
"P",
"o",
"l",
"y",
"B",
"a",
"s",
"e",
],
]

in the log output, instead of the expected

NumpydocParseError = [
    "numpy.polynomial._polybase:ABCPolyBase",

]

In general, tomllib is part of the standard library starting with Python 3.11, and the tomli package is a compatible version for lower Python versions. tomli_w is the version of the package with writing capabilities, and doesn't seem to have this issue.

However, I'm not super familiar with toml parsing so if there are other good reasons to stick with toml for writing, or if there are better alternatives, we can do that. tomlkit is another option as it supports round-tripping https://github.com/sdispater/tomlkit.

Carreau commented 1 year ago

Oh, thanks for finding this bug ! We can move the conditional dependency to a separate issue.