Skip to content

Commit 17f8c08

Browse files
authored
Use tomllib over toml for Python 3.11+
The uiri toml implementation doesn't support some minor features of TOML, such as "Not a homogeneous array". Given that tomllib is added to Python's stdlib, and supports the above feature, it should be loaded by default, and uiri's toml lib should be loaded as a backup
1 parent 32778bb commit 17f8c08

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

config/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
except ImportError: # pragma: no cover
1212
yaml = None
1313
try:
14-
import toml
14+
import tomllib as toml
15+
toml_readtype = "rb"
1516
except ImportError: # pragma: no cover
16-
toml = None
17+
try:
18+
import toml
19+
toml_readtype = "rt"
20+
except ImportError:
21+
toml = None
22+
toml_readtype = None
1723

1824

1925
from .configuration import Configuration
@@ -861,7 +867,7 @@ def _reload(self, data: Union[str, TextIO], read_from_file: bool = False) -> Non
861867
"""Reload the TOML data."""
862868
if read_from_file:
863869
if isinstance(data, str):
864-
with open(data, "rt") as f:
870+
with open(data, toml_readtype) as f:
865871
loaded = toml.load(f)
866872
else:
867873
loaded = toml.load(data)

0 commit comments

Comments
 (0)