Skip to content

Commit 88c9f31

Browse files
committed
Use the stdlib tomllib on python 3.11+
Although a tomli copy is vendored, doing this conditional import allows: - automatically upgrading the code, when the time comes to drop py3.10 support - slightly simplifying debundling support, as it's no longer necessary to depend on a tomli(-wheel)? package on sufficiently newer versions of python.
1 parent 47ffcdd commit 88c9f31

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

news/12797.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use tomllib from the stdlib if available, rather than tomli

src/pip/_internal/pyproject.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import importlib.util
22
import os
3+
import sys
34
from collections import namedtuple
45
from typing import Any, List, Optional
56

6-
from pip._vendor import tomli
7+
if sys.version_info >= (3, 11):
8+
import tomllib
9+
else:
10+
from pip._vendor import tomli as tomllib
11+
712
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
813

914
from pip._internal.exceptions import (
@@ -61,7 +66,7 @@ def load_pyproject_toml(
6166

6267
if has_pyproject:
6368
with open(pyproject_toml, encoding="utf-8") as f:
64-
pp_toml = tomli.loads(f.read())
69+
pp_toml = tomllib.loads(f.read())
6570
build_system = pp_toml.get("build-system")
6671
else:
6772
build_system = None

src/pip/_vendor/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def vendored(modulename):
111111
vendored("rich.text")
112112
vendored("rich.traceback")
113113
vendored("tenacity")
114-
vendored("tomli")
114+
if sys.version_info < (3, 11):
115+
vendored("tomli")
115116
vendored("truststore")
116117
vendored("urllib3")

0 commit comments

Comments
 (0)