Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ichard26 opened this issue Mar 24, 2022 · 2 comments · Fixed by #2926
Closed

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

ichard26 opened this issue Mar 24, 2022 · 2 comments · Fixed by #2926
Labels
C: unstable formatting Formatting changed on the second pass F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Mar 24, 2022

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
@ichard26 ichard26 added T: bug Something isn't working C: unstable formatting Formatting changed on the second pass F: parentheses Too many parentheses, not enough parentheses, and so on. labels Mar 24, 2022
@ichard26 ichard26 changed the title Removing multiple unnecessary parenthesizes Removing multiple unnecessary parenthesizes for for assignment targes is unstable Mar 24, 2022
@JelleZijlstra
Copy link
Collaborator

cc @jpy-git

@jpy-git
Copy link
Contributor

jpy-git commented Mar 24, 2022

As per @ichard26's comment this works when black performs a second pass but we want this to work in a single pass.

Similar issue here

Will take a look this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unstable formatting Formatting changed on the second pass F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants