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

Multi line if clauses #2599

Closed
Quappas opened this issue Nov 10, 2021 · 1 comment
Closed

Multi line if clauses #2599

Quappas opened this issue Nov 10, 2021 · 1 comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@Quappas
Copy link

Quappas commented Nov 10, 2021

Describe the style change

I write python modules that are configured by .yml files which look something like this:

Category_X:
  Subcategory_Y:
    Enable_Condition_Z: true

After reading them in, they are addressed like a nested dictionary (see below). Then I write if clauses that check if a condition is to be checked and if the condition is fulfilled. Black messes that up a bit.

Examples in the current Black style

def black_if_test():
    if complicated_settings_dict["Category_X"]["Subcategory_Y"][
        "Enable_Condition_Z"
    ] and fullfills_condition_Z(my_object):
        work()

Desired style

def black_if_test():
    if (
        complicated_settings_dict["Category_X"]["Subcategory_Y"]["Enable_Condition_Z"]
        and fullfills_condition_Z(my_object)
    ):
        work()

Additional context

Note that the line complicated_settings_dict["Category_X"]["Subcategory_Y"]["Enable_Condition_Z"] is only 86 characters long. I think black only wants to break it, because it wants to put the and on the same line. Putting the and on the next line (as for all binary operators) would make everything more readable in my opinion. In any case there is no reason here not to keep each condition I am checking for in its own single separate line.

@Quappas Quappas added the T: style What do we want Blackened code to look like? label Nov 10, 2021
@felix-hilden
Copy link
Collaborator

Hi, this is a duplicate of #2156, so let's continue the discussion there!

@felix-hilden felix-hilden added F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists labels Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants