Skip to content

Conversation

@Nikhil172913832
Copy link
Contributor

Description

Closes #4730

This PR addresses issue #4730, where # fmt: skip was being ignored or causing crashes in deeply nested expressions. The root cause is that Black's handling of fmt: skip converts AST nodes to string literals, which bypasses bracket tracking and can result in missing attributes like bracket_depth. This led to AttributeError exceptions, especially with extreme settings like --line-length=1.

Key changes:

  • Added hasattr(leaf, "bracket_depth") checks in src/black/lines.py to prevent crashes when processing leaves generated by fmt: skip.
  • Added a test (tests/data/cases/fmtskip_nested_expression.py) using the original code from the issue, without relying on the --no-preview-line-length-1 flag, as requested by maintainers.
  • Updated CHANGES.md to document the fix.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the
    stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

diff-shades reports zero changes comparing this PR (621b9ea) to main (2fd75b0).


What is this? | Workflow run | diff-shades documentation

@Nikhil172913832
Copy link
Contributor Author

Hi @cobaltt7, can you have a look at this PR when you get time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# fmt: skip ignored inside multi-part if-clause

1 participant