Skip to content

Commit d874785

Browse files
fix: add tomli fallback for Python 3.10 tomllib compatibility by dev-engineer
1 parent b133a10 commit d874785

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev = [
3434
"pytest>=7.0.0",
3535
"pytest-cov>=4.0.0",
3636
"ruff>=0.4.0",
37+
"tomli>=1.1.0; python_version < '3.11'",
3738
]
3839

3940
[project.urls]

tests/test_config_and_fixes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,10 @@ def test_ruff_known_first_party(self):
583583
"""ruff known-first-party should be ['deadcode'], not ['*']."""
584584
from pathlib import Path
585585

586-
import tomllib
586+
try:
587+
import tomllib # Python >=3.11
588+
except ModuleNotFoundError:
589+
import tomli as tomllib # Python 3.10 backport
587590

588591
pyproject = Path(__file__).parent.parent / "pyproject.toml"
589592
with open(pyproject, "rb") as f:
@@ -600,7 +603,10 @@ def test_package_data_includes_py_typed(self):
600603
"""pyproject.toml should have package-data config for py.typed."""
601604
from pathlib import Path
602605

603-
import tomllib
606+
try:
607+
import tomllib # Python >=3.11
608+
except ModuleNotFoundError:
609+
import tomli as tomllib # Python 3.10 backport
604610

605611
pyproject = Path(__file__).parent.parent / "pyproject.toml"
606612
with open(pyproject, "rb") as f:

0 commit comments

Comments
 (0)