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

Line too long: Attribute chain on right-hand side #1525

Closed
joaoe opened this issue Jun 30, 2020 · 5 comments
Closed

Line too long: Attribute chain on right-hand side #1525

joaoe opened this issue Jun 30, 2020 · 5 comments
Labels
F: linetoolong Black makes our lines too long F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like?

Comments

@joaoe
Copy link

joaoe commented Jun 30, 2020

Issue code (assume max line length <= 80):

    self.some_long_variable_name.some_property_name = self.some_other_property_name.some_long_value
    self.some_long_variable_name.some_property_name = self.some_other_property_name.some_long_method(some_parameter)

Black indents this as

    self.some_long_variable_name.some_property_name = self.some_other_property_name.some_long_value
    self.some_long_variable_name.some_property_name = self.some_other_property_name.some_long_method(
        some_parameter
    )

However, that first line still violates the line length limit.

Suggestion: use parenthesis:

    self.some_long_variable_name.some_property_name = (
        self.some_other_property_name.some_long_value
    )
    self.some_long_variable_name.some_property_name = (
        self.some_other_property_name.some_long_method(some_parameter)
    )
@joaoe joaoe added the T: enhancement New feature or request label Jun 30, 2020
@Paul-Aime
Copy link

To add on this, I have a similar case, where this:

da_outliers_loc = (
    (ds.precipitation > ds_qt.precipitation.sel(quantile=qt_values[0])) &
    (ds.temperature > ds_qt.temperature.sel(quantile=qt_values[1]))
)

is formatted like this: (tested in the black playground)

da_outliers_loc = (
    ds.precipitation > ds_qt.precipitation.sel(quantile=qt_values[0])
) & (ds.temperature > ds_qt.temperature.sel(quantile=qt_values[1]))

which is arguably uglier.

@JelleZijlstra JelleZijlstra added F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like? labels May 30, 2021
@ichard26 ichard26 removed the T: enhancement New feature or request label Jun 12, 2021
@Dr-Irv
Copy link

Dr-Irv commented Oct 8, 2021

Here's another example (taken from a colleagues' code - I renamed variables):

def outerfunc1(something):
    def outerfunc2(something_else):
        def innerfunc(another_thing):
            for row in another_thing.itertuples():
                try:
                    this_is_a_very_long_variablename = another_thing.sample(n=10)
                    this_is_a_very_long_variablename = this_is_a_very_long_variablename.loc[
                        this_is_a_very_long_variablename.a_pandas_long_column_nam.cumsum()
                        <= 10
                    ]
                except Exception:
                    raise ValueError("something")

could be reformatted as

def outerfunc1(something):
    def outerfunc2(something_else):
        def innerfunc(another_thing):
            for row in another_thing.itertuples():
                try:
                    this_is_a_very_long_variablename = another_thing.sample(n=10)
                    this_is_a_very_long_variablename = (
                        this_is_a_very_long_variablename.loc[
                            this_is_a_very_long_variablename.a_pandas_long_column_nam
                            .cumsum()
                            <= 10
                        ]
                    )
                except Exception:
                    raise ValueError("something")

@JelleZijlstra JelleZijlstra added the F: linetoolong Black makes our lines too long label Jan 29, 2022
@JelleZijlstra JelleZijlstra changed the title Parenthesize long lines Line too long: Attribute chain on right-hand side Jan 29, 2022
@yilei
Copy link
Contributor

yilei commented Oct 31, 2022

Triaging comments:

  1. Example from OP Line too long: Attribute chain on right-hand side #1525 (comment) is already fixed: playground link.
  2. Second example is a dup of Use optional parentheses more often #2156.
  3. I'm not sure third example is better, at least it's not related to OP.

@Dr-Irv
Copy link

Dr-Irv commented Oct 31, 2022

3. I'm not sure third example is better, at least it's not related to OP.

Should I create a new issue for that?

@JelleZijlstra
Copy link
Collaborator

I think #510 is enough and this one doesn't need to be kept open.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linetoolong Black makes our lines too long F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

6 participants