Repository: psf/black

Issue:
Internal Error ") :"
The formatter notices this bug itself, and politely asked me to file an issue:

```
INTERNAL ERROR: Black produced different code on the second pass of the formatter.  
Please report a bug on https://github.com/psf/black/issues.
```

Here's a repo:
1. take this file
```
very_long_variable_name = 0
very_very_long_variable_name = 1
extraordinarily_long_variable_name = 2

if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
    print("fubar")
```

2. format it, and get the error with the following log
```
--- source
+++ first pass
@@ -1,8 +1,10 @@
-
 very_long_variable_name = 0
 very_very_long_variable_name = 1
 extraordinarily_long_variable_name = 2
 
-if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
+if (
+    assignment_expression := very_long_variable_name + very_very_long_variable_name
+    > extraordinarily_long_variable_name
+):
     print("fubar")
 
--- first pass
+++ second pass
@@ -3,8 +3,8 @@
 extraordinarily_long_variable_name = 2
 
 if (
     assignment_expression := very_long_variable_name + very_very_long_variable_name
     > extraordinarily_long_variable_name
-):
+) :
     print("fubar")

```

- Version: black == 19.10b0
- OS and Python version: Linux/Python 3.8.5


Discussion:
Seems to be resolved on master?

https://black.now.sh/?version=master&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AE9AJxdAD2IimZxl1N_Wmp_J_tu2Yxt5S2uR7Vve9f5yNEzzTShAhCtvgdvqv04MD4kSBFn826X8RroICrEU1oEv00MLBkH4ky98TWUCpfdURQX8swoBa8CVft-6XTFZtoEgEOCb9RelK9R2Ox5OMPOpkB94cBaVCJlSltgSyyBCBxkBTZ268Aa_ksxMEsOcSUsyBGNRnHcx46jb1uJ_mgzrwD12i1h9jcpdQABuAG-AgAAsoGF9rHEZ_sCAAAAAARZWg==
> Seems to be resolved on master?

No :(
```console
(black-rHKUX7ap) R:\Programming\black>type test.py
very_long_variable_name = 0
very_very_long_variable_name = 1
extraordinarily_long_variable_name = 2

if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
    print("fubar")

(black-rHKUX7ap) R:\Programming\black>black test.py
error: cannot format test.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: C:\Users\User\AppData\Local\Temp\blk_hpuu4wvb.log
Oh no! 💥 💔 💥
1 file failed to reformat.
```

That's an UI issue with that site. It runs with `--fast` which is rarely used as `--safe` is the default. Ironically, running with `--fast` in this case was better than running with `--safe` but in most cases you should use `--safe` as it checks that it isn't producing bad code.

Edit: here's a [good example of why you **shouldn't use `--fast`**](https://black.now.sh/?version=master&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ACLAFhdAD2IimZxl1N_WlbvK5V9KEd0suDTtKdXxXy1j_BK0VXkurN0_QM5EtAsL9v3F7xurQV5mXojEbIWEYe-IZiNzJpDivFk5ncHhXeKZXRv6UG1vi3coSVS2AAAlHKiBZmXUaEAAXSMAQAAAPyhTJ-xxGf7AgAAAAAEWVo=)
Hmm, I was going to make a PR to Black Playground to remove `--fast`, but couldn't find it. Here's the config it uses:

https://github.com/jpadilla/black-playground/blob/439d825ae07fc478e0bce671973d295f46691884/api/app.py#L85-L90

Resolving patch:
diff --git a/src/black/__init__.py b/src/black/__init__.py
--- a/src/black/__init__.py
+++ b/src/black/__init__.py
@@ -5190,9 +5190,9 @@ def normalize_invisible_parens(node: Node, parens_after: Set[str]) -> None:
 
         if check_lpar:
             if is_walrus_assignment(child):
-                continue
+                pass
 
-            if child.type == syms.atom:
+            elif child.type == syms.atom:
                 if maybe_make_parens_invisible_in_atom(child, parent=node):
                     wrap_in_parentheses(node, child, visible=False)
             elif is_one_tuple(child):


Test patch:
diff --git a/tests/data/pep_572.py b/tests/data/pep_572.py
--- a/tests/data/pep_572.py
+++ b/tests/data/pep_572.py
@@ -2,6 +2,8 @@
 (a := a)
 if (match := pattern.search(data)) is None:
     pass
+if (match := pattern.search(data)):
+    pass
 [y := f(x), y ** 2, y ** 3]
 filtered_data = [y for x in data if (y := f(x)) is None]
 (y := f(x))
@@ -41,3 +43,5 @@ def foo(answer: (p := 42) = 5):
 
 while x := f(x):
     pass
+while (x := f(x)):
+    pass