Use tomllib on Python 3.11 (#2903)
This commit is contained in:
parent
24ffc54a53
commit
71e71e5f52
@ -48,6 +48,9 @@
|
|||||||
|
|
||||||
<!-- Changes to how Black is packaged, such as dependency requirements -->
|
<!-- Changes to how Black is packaged, such as dependency requirements -->
|
||||||
|
|
||||||
|
- On Python 3.11 and newer, use the standard library's `tomllib` instead of `tomli`
|
||||||
|
(#2903)
|
||||||
|
|
||||||
### Parser
|
### Parser
|
||||||
|
|
||||||
- Black can now parse starred expressions in the target of `for` and `async for`
|
- Black can now parse starred expressions in the target of `for` and `async for`
|
||||||
|
2
setup.py
2
setup.py
@ -99,7 +99,7 @@ def find_python_files(base: Path) -> List[Path]:
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
"click>=8.0.0",
|
"click>=8.0.0",
|
||||||
"platformdirs>=2",
|
"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'",
|
"typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'",
|
||||||
"pathspec>=0.9.0",
|
"pathspec>=0.9.0",
|
||||||
"dataclasses>=0.6; python_version < '3.7'",
|
"dataclasses>=0.6; python_version < '3.7'",
|
||||||
|
@ -20,7 +20,11 @@
|
|||||||
from mypy_extensions import mypyc_attr
|
from mypy_extensions import mypyc_attr
|
||||||
from pathspec import PathSpec
|
from pathspec import PathSpec
|
||||||
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
|
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.output import err
|
||||||
from black.report import Report
|
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]:
|
def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
|
||||||
"""Parse a pyproject toml file, pulling out relevant parts for Black
|
"""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:
|
with open(path_config, "rb") as f:
|
||||||
pyproject_toml = tomli.load(f)
|
pyproject_toml = tomllib.load(f)
|
||||||
config = pyproject_toml.get("tool", {}).get("black", {})
|
config = pyproject_toml.get("tool", {}).get("black", {})
|
||||||
return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
|
return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user