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

Unnecessary parentheses added to expression in indexed assignment #4349

Open
Pabloo22 opened this issue May 5, 2024 · 0 comments
Open

Unnecessary parentheses added to expression in indexed assignment #4349

Pabloo22 opened this issue May 5, 2024 · 0 comments
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working

Comments

@Pabloo22
Copy link

Pabloo22 commented May 5, 2024

Describe the bug

Black unnecessarily adds parentheses around the right-hand side expression in indexed assignments when breaking lines for long index names. This results in added visual clutter and does not conform to typical Python formatting standards where no additional parentheses would be expected. In particular, PyLint raises the superfluous-parens warning.

To Reproduce

Given the following Python script:

import numpy as np

def main():
    dictionary_of_arrays = {
        "long_key_name_for_the_example": np.zeros((3, 1)),
        "short": np.zeros((3, 1)),
    }
    index_zero = 0
    very_long_index_name = 1
    dictionary_of_arrays["long_key_name_for_the_example"][very_long_index_name, index_zero] = 10 - 5

When formatted using the online Black formatter at https://black.vercel.app/?version=main, the assignment line is formatted as follows:

dictionary_of_arrays["long_key_name_for_the_example"][
    very_long_index_name, index_zero
] = (10 - 5)

Expected behavior

The expected code should look like this:

dictionary_of_arrays["long_key_name_for_the_example"][
    very_long_index_name, index_zero
] = 10 - 5

Environment

  • Black's version: main (online formatter)
  • OS and Python version: N/A (used the online formatter)

Additional context

None.

@Pabloo22 Pabloo22 added the T: bug Something isn't working label May 5, 2024
@Pabloo22 Pabloo22 changed the title Unnecessary Parentheses Added to Expression in Indexed Assignment Unnecessary parentheses added to expression in indexed assignment May 5, 2024
@JelleZijlstra JelleZijlstra added the F: parentheses Too many parentheses, not enough parentheses, and so on. label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants