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

Formatter undocumented deviation: remove parenthesis #7320

Closed
JonathanPlasse opened this issue Sep 12, 2023 · 2 comments · Fixed by #7679
Closed

Formatter undocumented deviation: remove parenthesis #7320

JonathanPlasse opened this issue Sep 12, 2023 · 2 comments · Fixed by #7679
Assignees
Labels
documentation Improvements or additions to documentation formatter Related to the formatter

Comments

@JonathanPlasse
Copy link
Contributor

Black formatting

def update_emission_strength(self: "Lightshow", context: bpy.types.Context) -> None:  # noqa: ARG001
    (
        get_rgbw_emission_node_tree(self)
        .nodes["Emission"]
        .inputs["Strength"]
        .default_value  # pyright: ignore
    ) = (self.emission_strength * 2)

Ruff formatting

def update_emission_strength(self: "Lightshow", context: bpy.types.Context) -> None:  # noqa: ARG001
    (
        get_rgbw_emission_node_tree(self).nodes["Emission"].inputs["Strength"].default_value  # pyright: ignore
    ) = self.emission_strength * 2

Ruff 0.0.289, line-length 100

The pragma deviation is documented, but not the removal of parenthesis.

I prefer the Ruff formatting.

@MichaReiser
Copy link
Member

MichaReiser commented Sep 13, 2023

There are two differences here:

  1. Ruff splits the call chain differently because of the pyright: ignore comment. I think the current formatting is fine because enforcing black's layout can be wrong if you intend to document the whole call chain (and not just the last attribute).
  2. Black seems to parenthesize the right if the assignment target doesn't fit, regardless of whether the assigned value was parenthesized before. Adding these parentheses seems unnecessary in my view.
# Blacked code

def update_emission_strength():
    (
        get_rgbw_emission_node_tree(self)
        .nodes["Emission"]
        .inputs["Strength"]
        .default_value  # pyright: ignore
    ) = (self.emission_strength * 2)

    (
        get_rgbw_emission_node_tree(self)
        .nodes["Emission"]
        .inputs["Strength"]
        .default_value  # pyright: ignore
    ) = (self.emission_strength * 2)


def update_emission_strength():
    (get_rgbw_emission_node_tree(self).nodes["Emission"].default_value) = self.emission_strength * 2


def update_emission_strength():
    (get_rgbw_emission_node_tree(self).nodes["Emission"].default_valueeeeeeeeeeeeee) = (
        self.emission_strength * 2
    )


def update_emission_strength():
    (get_rgbw_emission_node_tree(self).nodes["Emission"].default_valueeeeeeeeeeeeee) = (
        self.emission_strength * 2
    )


def update_emission_strength():
    (
        get_rgbw_emission_node_tree(self)
        .nodes["Emission"]
        .default_valueeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
    ) = (self.emission_strength * 2)

@MichaReiser MichaReiser added wontfix This will not be worked on formatter Related to the formatter labels Sep 13, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Sep 13, 2023
@charliermarsh
Copy link
Member

The parentheses we're considering an intentional deviation. Can be closed once it's documented.

The comment positioning deviation is expected because we ignore suppression comments when computing line length. (If you change it to some other comment, we use the same formatting as Black, apart from the extra parentheses on the RHS.) We're not planning to change this for the Beta, but we'll revisit based on feedback around suppression comment handling more generally.

@charliermarsh charliermarsh self-assigned this Sep 27, 2023
@MichaReiser MichaReiser added documentation Improvements or additions to documentation and removed wontfix This will not be worked on labels Sep 28, 2023
charliermarsh added a commit that referenced this issue Sep 29, 2023
## Summary

Based on today's triage with @MichaReiser.

Closes #7652.
Closes #7320.
Closes #7052.
Closes #7314.
Closes #7317.
Closes #7323.
Closes #7320.
Closes #7315.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants