Skip to content

Commit af719d8

Browse files
authored
Merge pull request #12797 from eli-schwartz/stdlib-tomllib
Use the stdlib tomllib on python 3.11+
2 parents e238600 + 88c9f31 commit af719d8

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)