From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Tue, 8 Mar 2022 16:47:51 +0000 (-0800) Subject: Use tomllib on Python 3.11 (#2903) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/71e71e5f52e5f6bdeae63cc8c11b1bee44d11c30?ds=sidebyside;hp=24ffc54a53b52293a54d7ef9f2105c26e945cc67 Use tomllib on Python 3.11 (#2903) --- diff --git a/CHANGES.md b/CHANGES.md index 4264e63..edca0dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -48,6 +48,9 @@ +- On Python 3.11 and newer, use the standard library's `tomllib` instead of `tomli` + (#2903) + ### Parser - Black can now parse starred expressions in the target of `for` and `async for` diff --git a/setup.py b/setup.py index 466f1a9..6b5b957 100644 --- a/setup.py +++ b/setup.py @@ -99,7 +99,7 @@ setup( install_requires=[ "click>=8.0.0", "platformdirs>=2", - "tomli>=1.1.0", + "tomli>=1.1.0; python_version < '3.11'", "typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'", "pathspec>=0.9.0", "dataclasses>=0.6; python_version < '3.7'", diff --git a/src/black/files.py b/src/black/files.py index b6c1cf3..52c77c6 100644 --- a/src/black/files.py +++ b/src/black/files.py @@ -20,7 +20,11 @@ from typing import ( from mypy_extensions import mypyc_attr from pathspec import PathSpec from pathspec.patterns.gitwildmatch import GitWildMatchPatternError -import tomli + +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib from black.output import err from black.report import Report @@ -97,10 +101,10 @@ def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]: def parse_pyproject_toml(path_config: str) -> Dict[str, Any]: """Parse a pyproject toml file, pulling out relevant parts for Black - If parsing fails, will raise a tomli.TOMLDecodeError + If parsing fails, will raise a tomllib.TOMLDecodeError """ with open(path_config, "rb") as f: - pyproject_toml = tomli.load(f) + pyproject_toml = tomllib.load(f) config = pyproject_toml.get("tool", {}).get("black", {}) return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}