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

Output of func collected in tuple with long names skips indentation #4398

Closed
Zyantist opened this issue Jul 8, 2024 · 3 comments
Closed
Labels
T: bug Something isn't working

Comments

@Zyantist
Copy link

Zyantist commented Jul 8, 2024

Missing indentation in special combination of long names in a output collection in tuple

Hello! I may have found an issue with the formatting, where it does behave differently only in special cases.

After an automatic line break following the opening parenthesis of a function call, an indentation of 4 spaces is expected.
I tried this in several simplified versions (shorter names), where it worked as expected, but in the given example, the indentation does not occur.

I tested with the latest pip version of Black in Python 3.10, in the online formatter in the browser and with an editable install of the latest source code cloned from github [main] on Python 3.11.9.

""" myfile.py """
def fffffffffffffunc(*args):
    pass

ggggggggggg = None
hhhhhhhhhhhhhh = None
iiiiiiiiiiiiiiii = None
jjjjjjjjjjjjjjjj = None

(
    aaaaaaaaaaa,
    bbbbbbbb,
    cccccc,
    dddddddd,
    eeeeeeeeee,
) = fffffffffffffunc(
    ggggggggggg,
    hhhhhhhhhhhhhh,
    iiiiiiiiiiiiiiii,
    jjjjjjjjjjjjjjjj,
)

And run it with these arguments:

$ python -m black myfile.py

Tested with parameter target versions python 3.9 - 3.12.
Python executables used: versions 3.10 and Python 3.11.9.

The resulting error is:

Runs without error, but does not output the expected format.

Expected behavior

""" myfile.py """
def fffffffffffffunc(*args):
    pass

ggggggggggg = None
hhhhhhhhhhhhhh = None
iiiiiiiiiiiiiiii = None
jjjjjjjjjjjjjjjj = None

(
    aaaaaaaaaaa,
    bbbbbbbb,
    cccccc,
    dddddddd,
    eeeeeeeeee,
) = fffffffffffffunc(
        ggggggggggg,   # INDENTATION
        hhhhhhhhhhhhhh,
        iiiiiiiiiiiiiiii,
        jjjjjjjjjjjjjjjj,
)

Environment

  • Black's version: 24.4.2 (pipe) resp. main (online)
  • Fedora 39/40 and Python version 3.10:

Hope this helps and that I have not missed any limiting rules for the allowed length of variable names.

Thank you for all your appreciated work and efforts!

@Zyantist Zyantist added the T: bug Something isn't working label Jul 8, 2024
@JelleZijlstra
Copy link
Collaborator

This is the expected behavior; we only indent by one level in this case. Why do you think it should be different?

@Zyantist
Copy link
Author

Zyantist commented Jul 9, 2024

Thank you for your quick response. I see how this can be expected behaviour in a technical sense that one indent is added. I am not too deeply involved in these topics, but we work with Black in all our projects at my company, so I am used to the style, but this case just felt and feels very unnatural, as the function name starts at the same vertical line with its parameters.

Experimenting around, I noticed that this happens with short variable names too, if I use a trailing comma, but not if I avoid it, as in:

""" myfile.py """

(e, f, g, h, iiiiiiiiiiii) = calculate_things(
    a,
    b,
    c,
    d,
)

versus

(
    e,
    f,
    g,
    h,
    iiiiiiiiiiii,
) = calculate_things(
    a,
    b,
    c,
    d,
)

I suppose this would be better located in a style discussion, then.

@JelleZijlstra
Copy link
Collaborator

Yes, this is expected behavior and unlikely to change.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants