Skip to content

Commit

Permalink
Merge branch 'main' into psfgh-4143
Browse files Browse the repository at this point in the history
  • Loading branch information
cobaltt7 authored Jan 19, 2024
2 parents a231d50 + 9a331d6 commit 6ebdbd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Address a missing case in the change to allow empty lines at the beginning of all
blocks, except immediately before a docstring (#4130)
- For stubs, fix logic to enforce empty line after nested classes with bodies (#4141)
- Fix crash when using a walrus in a dictionary (#4155)

### Configuration

Expand Down
5 changes: 5 additions & 0 deletions docs/usage_and_configuration/the_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ recursive searches. An empty value means no paths are excluded. Use forward slas
directories on all platforms (Windows, too). By default, Black also ignores all paths
listed in `.gitignore`. Changing this value will override all default exclusions.

If the regular expression contains newlines, it is treated as a
[verbose regular expression](https://docs.python.org/3/library/re.html#re.VERBOSE). This
is typically useful when setting these options in a `pyproject.toml` configuration file;
see [Configuration format](#configuration-format) for more information.

#### `--extend-exclude`

Like `--exclude`, but adds additional files and directories on top of the default values
Expand Down
6 changes: 5 additions & 1 deletion src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ def visit_dictsetmaker(self, node: Node) -> Iterator[Line]:
if i == 0:
continue
if node.children[i - 1].type == token.COLON:
if child.type == syms.atom and child.children[0].type == token.LPAR:
if (
child.type == syms.atom
and child.children[0].type == token.LPAR
and not is_walrus_assignment(child)
):
if maybe_make_parens_invisible_in_atom(
child,
parent=node,
Expand Down
7 changes: 7 additions & 0 deletions tests/data/cases/walrus_in_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# flags: --preview
{
"is_update": (up := commit.hash in update_hashes)
}

# output
{"is_update": (up := commit.hash in update_hashes)}

0 comments on commit 6ebdbd8

Please sign in to comment.