Skip to content

Commit 110ba4c

Browse files
committed
prefer newer "tomllib" over "tomli" backport
1 parent 9f13289 commit 110ba4c

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

lib/ts_utils/metadata.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from typing import Annotated, Any, Final, NamedTuple, final
1616
from typing_extensions import TypeGuard
1717

18-
import tomli
18+
try:
19+
import tomllib
20+
except ImportError:
21+
import tomli as tomllib
22+
1923
import tomlkit
2024
from packaging.requirements import Requirement
2125
from packaging.specifiers import Specifier
@@ -52,7 +56,7 @@ def _is_nested_dict(obj: object) -> TypeGuard[dict[str, dict[str, Any]]]:
5256
@functools.cache
5357
def get_oldest_supported_python() -> str:
5458
with PYPROJECT_PATH.open("rb") as config:
55-
val = tomli.load(config)["tool"]["typeshed"]["oldest_supported_python"]
59+
val = tomllib.load(config)["tool"]["typeshed"]["oldest_supported_python"]
5660
assert type(val) is str
5761
return val
5862

@@ -92,7 +96,7 @@ def system_requirements_for_platform(self, platform: str) -> list[str]:
9296
def read_stubtest_settings(distribution: str) -> StubtestSettings:
9397
"""Return an object describing the stubtest settings for a single stubs distribution."""
9498
with metadata_path(distribution).open("rb") as f:
95-
data: dict[str, object] = tomli.load(f).get("tool", {}).get("stubtest", {})
99+
data: dict[str, object] = tomllib.load(f).get("tool", {}).get("stubtest", {})
96100

97101
skip: object = data.get("skip", False)
98102
apt_dependencies: object = data.get("apt_dependencies", [])

lib/ts_utils/mypy.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from contextlib import contextmanager
55
from typing import Any, NamedTuple
66

7-
import tomli
7+
try:
8+
import tomllib
9+
except ImportError:
10+
import tomli as tomllib
811

912
from ts_utils.metadata import StubtestSettings, metadata_path
1013
from ts_utils.utils import NamedTemporaryFile, TemporaryFileWrapper
@@ -26,7 +29,7 @@ class MypyDistConf(NamedTuple):
2629

2730
def mypy_configuration_from_distribution(distribution: str) -> list[MypyDistConf]:
2831
with metadata_path(distribution).open("rb") as f:
29-
data = tomli.load(f)
32+
data = tomllib.load(f)
3033

3134
# TODO: This could be added to ts_utils.metadata
3235
mypy_tests_conf: dict[str, dict[str, Any]] = data.get("mypy-tests", {})

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ruff==0.12.2
1919
# TODO (2025-05-07): Dependency libcst doesn't support Python 3.14 yet.
2020
stubdefaulter==0.1.0; python_version < "3.14"
2121
termcolor>=2.3
22-
tomli==2.2.1
22+
tomli==2.2.1; python_version < "3.11"
2323
tomlkit==0.13.3
2424
typing_extensions>=4.14.0rc1
2525
uv==0.7.19

scripts/stubsabot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
from typing import Annotated, Any, ClassVar, NamedTuple, TypeVar
2626
from typing_extensions import Self, TypeAlias
2727

28+
try:
29+
import tomllib
30+
except ImportError:
31+
import tomli as tomllib
32+
2833
import aiohttp
2934
import packaging.version
30-
import tomli
3135
import tomlkit
3236
from packaging.specifiers import Specifier
3337
from termcolor import colored
@@ -536,7 +540,7 @@ def parse_no_longer_updated_from_archive(source: zipfile.ZipFile | tarfile.TarFi
536540
return False
537541

538542
with file as f:
539-
toml_data: dict[str, object] = tomli.load(f)
543+
toml_data: dict[str, object] = tomllib.load(f)
540544

541545
no_longer_updated = toml_data.get("no_longer_updated", False)
542546
assert type(no_longer_updated) is bool

0 commit comments

Comments
 (0)