From 0c2064728eb1f4ba2b063182e023924b799a9fac Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 30 Nov 2023 20:16:55 -0500 Subject: [PATCH] use the standard library tomllib on sufficiently new python In python 3.11 it is no longer necessary to vendor (?) a toml implementation. The vendored one is now part of the standard library. Simply use that instead. Benefits include: - micro-optimization when using the isort library API in an application that already uses tomllib, to avoid reading yet another one from on-disk - seamless support for automatically dropping tomli once the minimum python version is upgraded, via tools such as pyupgrade - distributors who patch out isort to use the system tomli, do not actually have to package tomli for versions of python that have tomllib --- isort/settings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/isort/settings.py b/isort/settings.py index 2c6b94bc..a3658fff 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -45,9 +45,12 @@ from .wrap_modes import from_string as wrap_mode_from_string if TYPE_CHECKING: - tomli: Any + tomllib: Any else: - from ._vendored import tomli + if sys.version_info >= (3, 11): + import tomllib + else: + from ._vendored import tomli as tomllib _SHEBANG_RE = re.compile(rb"^#!.*\bpython[23w]?\b") CYTHON_EXTENSIONS = frozenset({"pyx", "pxd"}) @@ -831,7 +834,7 @@ def _get_config_data(file_path: str, sections: Tuple[str, ...]) -> Dict[str, Any if file_path.endswith(".toml"): with open(file_path, "rb") as bin_config_file: - config = tomli.load(bin_config_file) + config = tomllib.load(bin_config_file) for section in sections: config_section = config for key in section.split("."):