Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<!-- Changes that affect Black's stable style -->

- Fix crash when a leaf's bracket metadata is read before bracket tracking has visited
it (#5215)
- Fix crash when a standalone comment sits between tokens of a comprehension or lambda
(#5144)
- Fix crash when a comment-only `# fmt: off`/`# fmt: on` block is followed by a `with`
Expand Down
1 change: 1 addition & 0 deletions src/blib2to3/pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def __init__(
self._prefix = prefix
self.fixers_applied: list[Any] | None = fixers_applied[:]
self.children = []
self.bracket_depth = 0
self.opening_bracket = opening_bracket
self.fmt_pass_converted_first_leaf = fmt_pass_converted_first_leaf

Expand Down
14 changes: 14 additions & 0 deletions tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

import black
from blib2to3.pgen2 import token, tokenize
from blib2to3.pytree import Leaf

if sys.version_info >= (3, 11):
from typing import assert_type
else:
from typing_extensions import assert_type


@dataclass
Expand All @@ -30,6 +36,14 @@ def assert_tokenizes(text: str, tokens: list[Token]) -> None:
assert actual_tokens == tokens


def test_leaf_initializes_bracket_metadata() -> None:
leaf = Leaf(token.NAME, "name")

assert_type(leaf.bracket_depth, int)
assert leaf.bracket_depth == 0
assert leaf.opening_bracket is None


def test_simple() -> None:
assert_tokenizes(
"1",
Expand Down