Skip to content

Commit

Permalink
Move to preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rdrll committed Mar 9, 2024
1 parent 9b67dfb commit 6042717
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGES.md
Expand Up @@ -11,13 +11,14 @@
<!-- Changes that affect Black's stable style -->

- Don't move comments along with delimiters, which could cause crashes (#4248)
- Fixed a bug where `if` clauses in `match-case` blocks are not wrapped with parenthesis
when the line is too long (#4269)

### Preview style

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

- Fixed a bug where `if` clauses in `match-case` blocks are not wrapped with parenthesis
when the line is too long (#4269)

### Configuration

<!-- Changes to how Black can be configured -->
Expand Down
2 changes: 2 additions & 0 deletions docs/the_black_code_style/future_style.md
Expand Up @@ -34,6 +34,8 @@ Currently, the following features are included in the preview style:
quotes of a docstring
- `remove_redundant_guard_parens`: Removes redundant parentheses in `if` guards for
`case` blocks.
- `parens_for_long_if_clauses_in_case_block`: Fixed a bug where `if` clauses in
`match-case` blocks are not wrapped with parenthesis when the line is too long

(labels/unstable-features)=

Expand Down
8 changes: 6 additions & 2 deletions src/black/linegen.py
Expand Up @@ -1311,8 +1311,12 @@ def normalize_invisible_parens( # noqa: C901
)

# Fixes a bug where invisible parens are not properly wrapped around
# if statement.
if isinstance(child, Node) and child.type == syms.guard:
# if statement when line is too long.
if (
isinstance(child, Node)
and child.type == syms.guard
and Preview.parens_for_long_if_clauses_in_case_block in mode
):
normalize_invisible_parens(
child, parens_after={"if"}, mode=mode, features=features
)
Expand Down
1 change: 1 addition & 0 deletions src/black/mode.py
Expand Up @@ -180,6 +180,7 @@ class Preview(Enum):
is_simple_lookup_for_doublestar_expression = auto()
docstring_check_for_newline = auto()
remove_redundant_guard_parens = auto()
parens_for_long_if_clauses_in_case_block = auto()


UNSTABLE_FEATURES: Set[Preview] = {
Expand Down
3 changes: 2 additions & 1 deletion src/black/resources/black.schema.json
Expand Up @@ -88,7 +88,8 @@
"typed_params_trailing_comma",
"is_simple_lookup_for_doublestar_expression",
"docstring_check_for_newline",
"remove_redundant_guard_parens"
"remove_redundant_guard_parens",
"parens_for_long_if_clauses_in_case_block"
]
},
"description": "Enable specific features included in the `--unstable` style. Requires `--preview`. No compatibility guarantees are provided on the behavior or existence of any unstable features."
Expand Down
2 changes: 1 addition & 1 deletion tests/data/cases/pattern_matching_with_if_stmt.py
@@ -1,4 +1,4 @@
# flags: --minimum-version=3.10
# flags: --preview --minimum-version=3.10
match "test":
case "test" if "first long condition" != "some loooooooooooooooooooooooooooooooooooooog condition":
print("Test")
Expand Down

0 comments on commit 6042717

Please sign in to comment.