Skip to content

Commit a5fe910

Browse files
committed
fix(toml): complete migration off uiri/toml; add tomli for Py3.10 decode
Per maintainer review (CHANGES_REQUESTED, fabiocaccamo): replace abandoned uiri/toml dependency with tomli (Python 3.10) + tomllib (Python 3.11+). Encode side stays on tomli_w (no change). Net: uiri/toml fully removed. Fix mypy CI gate: - benedict/serializers/toml.py:52 — explicit str annotation on tomli_w.dumps() return value to satisfy [no-any-return] check. Auxiliary test file rename + typo fix: - tests/dicts/io/test_io_dict_toml.py — patched flag renamed toml_installed -> tomli_installed; "tomlib" -> "tomllib" in skip-message. Verified locally: pre-commit clean (9/9 hooks pass including mypy); pytest tests/serializers/test_toml_serializer.py + tests/dicts/io/test_io_dict_toml.py 21 passed, 1 skipped (skip is correct — tomllib available on Py3.11+).
1 parent fab8096 commit a5fe910

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

benedict/serializers/toml.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
try:
2-
import toml
2+
# python >= 3.11
3+
import tomllib
34

4-
toml_installed = True
5+
tomllib_available = True
6+
except ImportError:
7+
tomllib_available = False
8+
9+
try:
10+
import tomli
11+
12+
tomli_installed = True
513
except ModuleNotFoundError:
6-
toml_installed = False
14+
tomli_installed = False
715

816
try:
917
import tomli_w
@@ -12,14 +20,6 @@
1220
except ModuleNotFoundError:
1321
tomli_w_installed = False
1422

15-
try:
16-
# python >= 3.11
17-
import tomllib
18-
19-
tomllib_available = True
20-
except ImportError:
21-
tomllib_available = False
22-
2323
from typing import Any
2424

2525
from benedict.extras import require_toml
@@ -42,11 +42,11 @@ def decode(self, s: str, **kwargs: Any) -> Any:
4242
if tomllib_available:
4343
data = tomllib.loads(s, **kwargs)
4444
else:
45-
require_toml(installed=toml_installed)
46-
data = toml.loads(s, **kwargs)
45+
require_toml(installed=tomli_installed)
46+
data = tomli.loads(s, **kwargs)
4747
return data
4848

4949
def encode(self, d: Any, **kwargs: Any) -> str:
5050
require_toml(installed=tomli_w_installed)
51-
data = tomli_w.dumps(dict(d), **kwargs)
52-
return data
51+
result: str = tomli_w.dumps(dict(d), **kwargs)
52+
return result

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ s3 = [
138138
"boto3 >= 1.24.89, < 2.0.0",
139139
]
140140
toml = [
141-
"toml >= 0.10.2, < 1.0.0; python_version < '3.11'",
141+
"tomli >= 2.0.0, < 3.0.0; python_version < '3.11'",
142142
"tomli-w >= 1.0.0, < 2.0.0",
143143
]
144144
xls = [

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ python-fsutil == 0.16.1
1111
python-slugify == 8.0.4
1212
pyyaml == 6.0.3
1313
requests == 2.33.1
14-
toml == 0.10.2
14+
tomli == 2.0.2
1515
tomli-w == 1.2.0
1616
typing_extensions >= 4.14.1
1717
urllib3 >= 2.6.3

tests/dicts/io/test_io_dict_toml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def test_from_toml_with_valid_data(self) -> None:
5050

5151
@unittest.skipIf(
5252
tomllib_available,
53-
"standard tomlib is available, exception will not be raised",
53+
"standard tomllib is available, exception will not be raised",
5454
)
55-
@patch("benedict.serializers.toml.toml_installed", False)
55+
@patch("benedict.serializers.toml.tomli_installed", False)
5656
def test_from_toml_with_valid_data_but_toml_extra_not_installed(self) -> None:
5757
j = """
5858
a = 1

0 commit comments

Comments
 (0)