Skip to content

Commit

Permalink
Update contrib/python/black to 25.1.0
Browse files Browse the repository at this point in the history
commit_hash:1d868f3afe3ed85f1cb0cf7e155f28fa33f81f19
  • Loading branch information
robot-piglet committed Feb 25, 2025
1 parent a6b7442 commit 752a499
Show file tree
Hide file tree
Showing 28 changed files with 329 additions and 241 deletions.
63 changes: 58 additions & 5 deletions contrib/python/black/.dist-info/METADATA
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Metadata-Version: 2.3
Metadata-Version: 2.4
Name: black
Version: 24.10.0
Version: 25.1.0
Summary: The uncompromising code formatter.
Project-URL: Documentation, https://black.readthedocs.io/
Project-URL: Changelog, https://github.com/psf/black/blob/main/CHANGES.md
Project-URL: Repository, https://github.com/psf/black
Project-URL: Issues, https://github.com/psf/black/issues
Author-email: Łukasz Langa <[email protected]>
License: MIT
License-Expression: MIT
License-File: AUTHORS.md
License-File: LICENSE
Keywords: automation,autopep8,formatter,gofmt,pyfmt,rustfmt,yapf
Expand Down Expand Up @@ -84,7 +84,7 @@ Try it out now using the [Black Playground](https://black.vercel.app). Watch the

### Installation

_Black_ can be installed by running `pip install black`. It requires Python 3.8+ to run.
_Black_ can be installed by running `pip install black`. It requires Python 3.9+ to run.
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.

If you can't wait for the latest _hotness_ and want to install from GitHub, use:
Expand Down Expand Up @@ -183,7 +183,7 @@ SQLAlchemy, Poetry, PyPA applications (Warehouse, Bandersnatch, Pipenv, virtuale
pandas, Pillow, Twisted, LocalStack, every Datadog Agent Integration, Home Assistant,
Zulip, Kedro, OpenOA, FLORIS, ORBIT, WOMBAT, and many more.

The following organizations use _Black_: Facebook, Dropbox, KeepTruckin, Lyft, Mozilla,
The following organizations use _Black_: Dropbox, KeepTruckin, Lyft, Mozilla,
Quora, Duolingo, QuantumBlack, Tesla, Archer Aviation.

Are we missing anyone? Let us know.
Expand Down Expand Up @@ -276,6 +276,59 @@ Flying Circus is expected. We are not savages.
And if you _really_ need to slap somebody, do it with a fish while dancing.
# Change Log

## 25.1.0

### Highlights

This release introduces the new 2025 stable style (#4558), stabilizing
the following changes:

- Normalize casing of Unicode escape characters in strings to lowercase (#2916)
- Fix inconsistencies in whether certain strings are detected as docstrings (#4095)
- Consistently add trailing commas to typed function parameters (#4164)
- Remove redundant parentheses in if guards for case blocks (#4214)
- Add parentheses to if clauses in case blocks when the line is too long (#4269)
- Whitespace before `# fmt: skip` comments is no longer normalized (#4146)
- Fix line length computation for certain expressions that involve the power operator (#4154)
- Check if there is a newline before the terminating quotes of a docstring (#4185)
- Fix type annotation spacing between `*` and more complex type variable tuple (#4440)

The following changes were not in any previous release:

- Remove parentheses around sole list items (#4312)
- Generic function definitions are now formatted more elegantly: parameters are
split over multiple lines first instead of type parameter definitions (#4553)

### Stable style

- Fix formatting cells in IPython notebooks with magic methods and starting or trailing
empty lines (#4484)
- Fix crash when formatting `with` statements containing tuple generators/unpacking
(#4538)

### Preview style

- Fix/remove string merging changing f-string quotes on f-strings with internal quotes
(#4498)
- Collapse multiple empty lines after an import into one (#4489)
- Prevent `string_processing` and `wrap_long_dict_values_in_parens` from removing
parentheses around long dictionary values (#4377)
- Move `wrap_long_dict_values_in_parens` from the unstable to preview style (#4561)

### Packaging

- Store license identifier inside the `License-Expression` metadata field, see
[PEP 639](https://peps.python.org/pep-0639/). (#4479)

### Performance

- Speed up the `is_fstring_start` function in Black's tokenizer (#4541)

### Integrations

- If using stdin with `--stdin-filename` set to a force excluded path, stdin won't be
formatted. (#4539)

## 24.10.0

### Highlights
Expand Down
4 changes: 2 additions & 2 deletions contrib/python/black/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Try it out now using the [Black Playground](https://black.vercel.app). Watch the

### Installation

_Black_ can be installed by running `pip install black`. It requires Python 3.8+ to run.
_Black_ can be installed by running `pip install black`. It requires Python 3.9+ to run.
If you want to format Jupyter Notebooks, install with `pip install "black[jupyter]"`.

If you can't wait for the latest _hotness_ and want to install from GitHub, use:
Expand Down Expand Up @@ -137,7 +137,7 @@ SQLAlchemy, Poetry, PyPA applications (Warehouse, Bandersnatch, Pipenv, virtuale
pandas, Pillow, Twisted, LocalStack, every Datadog Agent Integration, Home Assistant,
Zulip, Kedro, OpenOA, FLORIS, ORBIT, WOMBAT, and many more.

The following organizations use _Black_: Facebook, Dropbox, KeepTruckin, Lyft, Mozilla,
The following organizations use _Black_: Dropbox, KeepTruckin, Lyft, Mozilla,
Quora, Duolingo, QuantumBlack, Tesla, Archer Aviation.

Are we missing anyone? Let us know.
Expand Down
2 changes: 1 addition & 1 deletion contrib/python/black/_black_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "24.10.0"
version = "25.1.0"
26 changes: 15 additions & 11 deletions contrib/python/black/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
import sys
import tokenize
import traceback
from contextlib import contextmanager
from dataclasses import replace
from datetime import datetime, timezone
from enum import Enum
from json.decoder import JSONDecodeError
from pathlib import Path
from typing import (
Any,
from collections.abc import (
Collection,
Generator,
Iterator,
MutableMapping,
Optional,
Pattern,
Sequence,
Sized,
Union,
)
from contextlib import contextmanager
from dataclasses import replace
from datetime import datetime, timezone
from enum import Enum
from json.decoder import JSONDecodeError
from pathlib import Path
from re import Pattern
from typing import Any, Optional, Union

import click
from click.core import ParameterSource
Expand Down Expand Up @@ -751,6 +749,12 @@ def get_sources(
for s in src:
if s == "-" and stdin_filename:
path = Path(stdin_filename)
if path_is_excluded(stdin_filename, force_exclude):
report.path_ignored(
path,
"--stdin-filename matches the --force-exclude regular expression",
)
continue
is_stdin = True
else:
path = Path(s)
Expand Down
3 changes: 2 additions & 1 deletion contrib/python/black/black/brackets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Builds on top of nodes.py to track brackets."""

from collections.abc import Iterable, Sequence
from dataclasses import dataclass, field
from typing import Final, Iterable, Optional, Sequence, Union
from typing import Final, Optional, Union

from black.nodes import (
BRACKET,
Expand Down
3 changes: 2 additions & 1 deletion contrib/python/black/black/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import pickle
import sys
import tempfile
from collections.abc import Iterable
from dataclasses import dataclass, field
from pathlib import Path
from typing import Iterable, NamedTuple
from typing import NamedTuple

from platformdirs import user_cache_dir

Expand Down
11 changes: 4 additions & 7 deletions contrib/python/black/black/comments.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import re
from collections.abc import Collection, Iterator
from dataclasses import dataclass
from functools import lru_cache
from typing import Collection, Final, Iterator, Optional, Union
from typing import Final, Optional, Union

from black.mode import Mode, Preview
from black.mode import Mode
from black.nodes import (
CLOSING_BRACKETS,
STANDALONE_COMMENT,
Expand Down Expand Up @@ -234,11 +235,7 @@ def convert_one_fmt_off_pair(
standalone_comment_prefix += fmt_off_prefix
hidden_value = comment.value + "\n" + hidden_value
if is_fmt_skip:
hidden_value += (
comment.leading_whitespace
if Preview.no_normalize_fmt_skip_whitespace in mode
else " "
) + comment.value
hidden_value += comment.leading_whitespace + comment.value
if hidden_value.endswith("\n"):
# That happens when one of the `ignored_nodes` ended with a NEWLINE
# leaf (possibly followed by a DEDENT).
Expand Down
3 changes: 2 additions & 1 deletion contrib/python/black/black/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import signal
import sys
import traceback
from collections.abc import Iterable
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
from multiprocessing import Manager
from pathlib import Path
from typing import Any, Iterable, Optional
from typing import Any, Optional

from mypy_extensions import mypyc_attr

Expand Down
3 changes: 2 additions & 1 deletion contrib/python/black/black/debug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Iterator
from dataclasses import dataclass, field
from typing import Any, Iterator, TypeVar, Union
from typing import Any, TypeVar, Union

from black.nodes import Visitor
from black.output import out
Expand Down
13 changes: 3 additions & 10 deletions contrib/python/black/black/files.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import io
import os
import sys
from collections.abc import Iterable, Iterator, Sequence
from functools import lru_cache
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Iterable,
Iterator,
Optional,
Pattern,
Sequence,
Union,
)
from re import Pattern
from typing import TYPE_CHECKING, Any, Optional, Union

from mypy_extensions import mypyc_attr
from packaging.specifiers import InvalidSpecifier, Specifier, SpecifierSet
Expand Down
31 changes: 21 additions & 10 deletions contrib/python/black/black/handle_ipynb_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"time",
"timeit",
))
TOKEN_HEX = secrets.token_hex


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -160,7 +159,7 @@ def mask_cell(src: str) -> tuple[str, list[Replacement]]:
becomes
"25716f358c32750e"
b"25716f358c32750"
'foo'
The replacements are returned, along with the transformed code.
Expand All @@ -178,18 +177,32 @@ def mask_cell(src: str) -> tuple[str, list[Replacement]]:
from IPython.core.inputtransformer2 import TransformerManager

transformer_manager = TransformerManager()
# A side effect of the following transformation is that it also removes any
# empty lines at the beginning of the cell.
transformed = transformer_manager.transform_cell(src)
transformed, cell_magic_replacements = replace_cell_magics(transformed)
replacements += cell_magic_replacements
transformed = transformer_manager.transform_cell(transformed)
transformed, magic_replacements = replace_magics(transformed)
if len(transformed.splitlines()) != len(src.splitlines()):
if len(transformed.strip().splitlines()) != len(src.strip().splitlines()):
# Multi-line magic, not supported.
raise NothingChanged
replacements += magic_replacements
return transformed, replacements


def create_token(n_chars: int) -> str:
"""Create a randomly generated token that is n_chars characters long."""
assert n_chars > 0
n_bytes = max(n_chars // 2 - 1, 1)
token = secrets.token_hex(n_bytes)
if len(token) + 3 > n_chars:
token = token[:-1]
# We use a bytestring so that the string does not get interpreted
# as a docstring.
return f'b"{token}"'


def get_token(src: str, magic: str) -> str:
"""Return randomly generated token to mask IPython magic with.
Expand All @@ -199,21 +212,19 @@ def get_token(src: str, magic: str) -> str:
not already present anywhere else in the cell.
"""
assert magic
nbytes = max(len(magic) // 2 - 1, 1)
token = TOKEN_HEX(nbytes)
n_chars = len(magic)
token = create_token(n_chars)
counter = 0
while token in src:
token = TOKEN_HEX(nbytes)
token = create_token(n_chars)
counter += 1
if counter > 100:
raise AssertionError(
"INTERNAL ERROR: Black was not able to replace IPython magic. "
"Please report a bug on https://github.com/psf/black/issues. "
f"The magic might be helpful: {magic}"
) from None
if len(token) + 2 < len(magic):
token = f"{token}."
return f'"{token}"'
return token


def replace_cell_magics(src: str) -> tuple[str, list[Replacement]]:
Expand Down Expand Up @@ -269,7 +280,7 @@ def replace_magics(src: str) -> tuple[str, list[Replacement]]:
magic_finder = MagicFinder()
magic_finder.visit(ast.parse(src))
new_srcs = []
for i, line in enumerate(src.splitlines(), start=1):
for i, line in enumerate(src.split("\n"), start=1):
if i in magic_finder.magics:
offsets_and_magics = magic_finder.magics[i]
if len(offsets_and_magics) != 1: # pragma: nocover
Expand Down
Loading

0 comments on commit 752a499

Please sign in to comment.