Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable universal newlines when reading TOML #2408

Merged
merged 10 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### _Black_

- Do not accept bare carriage return line endings in pyproject.toml (#2408)
- Improve error message for invalid regular expression (#2678)
- Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}`
(#2686)
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ platformdirs= ">=2"
click = ">=8.0.0"
mypy_extensions = ">=0.4.3"
pathspec = ">=0.8.1"
tomli = ">=0.2.6, <2.0.0"
tomli = ">=1.1.0, <3.0.0"
typed-ast = "==1.4.3"
typing_extensions = {markers = "python_version < '3.10'", version = ">=3.10.0.0"}
black = {editable = true,extras = ["d"],path = "."}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def find_python_files(base: Path) -> List[Path]:
install_requires=[
"click>=7.1.2",
"platformdirs>=2",
"tomli>=0.2.6,<2.0.0",
"tomli>=1.1.0,<3.0.0",
"typed-ast>=1.4.2; python_version < '3.8' and implementation_name == 'cpython'",
"pathspec>=0.9.0, <1",
"dataclasses>=0.6; python_version < '3.7'",
Expand Down
4 changes: 2 additions & 2 deletions src/black/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:

If parsing fails, will raise a tomli.TOMLDecodeError
"""
with open(path_config, encoding="utf8") as f:
pyproject_toml = tomli.loads(f.read())
with open(path_config, "rb") as f:
pyproject_toml = tomli.load(f)
config = pyproject_toml.get("tool", {}).get("black", {})
return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}

Expand Down