Skip to content

Commit 2e8a319

Browse files
authored
Use tomllib on Python 3.11 (#9741)
1 parent 752a059 commit 2e8a319

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

changelog/9741.improvement.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
On Python 3.11, use the standard library's :mod:`tomllib` to parse TOML.
2+
3+
:mod:`tomli`` is no longer a dependency on Python 3.11.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ install_requires =
4646
packaging
4747
pluggy>=0.12,<2.0
4848
py>=1.8.2
49-
tomli>=1.0.0
5049
atomicwrites>=1.0;sys_platform=="win32"
5150
colorama;sys_platform=="win32"
5251
importlib-metadata>=0.12;python_version<"3.8"
52+
tomli>=1.0.0;python_version<"3.11"
5353
python_requires = >=3.7
5454
package_dir =
5555
=src

src/_pytest/config/findpaths.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
from pathlib import Path
34
from typing import Dict
45
from typing import Iterable
@@ -64,12 +65,15 @@ def load_config_dict_from_file(
6465

6566
# '.toml' files are considered if they contain a [tool.pytest.ini_options] table.
6667
elif filepath.suffix == ".toml":
67-
import tomli
68+
if sys.version_info >= (3, 11):
69+
import tomllib
70+
else:
71+
import tomli as tomllib
6872

6973
toml_text = filepath.read_text(encoding="utf-8")
7074
try:
71-
config = tomli.loads(toml_text)
72-
except tomli.TOMLDecodeError as exc:
75+
config = tomllib.loads(toml_text)
76+
except tomllib.TOMLDecodeError as exc:
7377
raise UsageError(f"{filepath}: {exc}") from exc
7478

7579
result = config.get("tool", {}).get("pytest", {}).get("ini_options", None)

0 commit comments

Comments
 (0)