Skip to content

Removing multiple unnecessary parenthesizes for for assignment targes is unstable #2952

@ichard26

Description

@ichard26

Describe the bug

Under preview, the removal of unnecessary parenthesizes can be unstable if there's multiple -- each pass removes only one pair.

To Reproduce

For example, take this code:

for ((x, y)) in enumerate(range(10)):
    pass

And run it with these arguments:

$ black file.py --preview

The resulting error is:

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: /tmp/blk_473_benq.log

Oh no! 💥 💔 💥
1 file would fail to reformat.

Mode(target_versions={<TargetVersion.PY38: 8>, <TargetVersion.PY37: 7>, <TargetVersion.PY36: 6>}, line_length=88, string_normalization=True, is_pyi=False, is_ipynb=False, magic_trailing_comma=True, experimental_string_processing=False, python_cell_magics=set(), preview=True)
--- source
+++ first pass
@@ -1,2 +1,2 @@
-for ((x, y)) in enumerate(range(10)):
+for (x, y) in enumerate(range(10)):
     pass
--- first pass
+++ second pass
@@ -1,2 +1,2 @@
-for (x, y) in enumerate(range(10)):
+for x, y in enumerate(range(10)):
     pass

Expected behavior

All of the unnecessary parenthesizes being removed at once ^^

Environment

  • Black's version: 14d84ba
  • OS and Python version: CPython 3.8.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: unstable formattingFormatting changed on the second passF: parenthesesToo many parentheses, not enough parentheses, and so on.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions