-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 #510
Comments
I'm seeing this issue also. Here's a more minimal example:
I tried it with parentheses, but that removes the trailing comma:
That latter part is perhaps another issue, maybe #493. |
I have a case where Black 19.3b0 removes a backslash and a newline to make the line over the limit: Inputclass Thing:
def get(self):
typ = 1
if True:
if True:
if True:
for i in range(0, 10):
try:
abcd_efgh, ijklmno =\
AaaaBbbbbCccccc.DddddEeeeFffffffff_gg._hhhh_iiiiiii[
typ
]
except KeyError:
continue Outputclass Thing:
def get(self):
typ = 1
if True:
if True:
if True:
for i in range(0, 10):
try:
abcd_efgh, ijklmno = AaaaBbbbbCccccc.DddddEeeeFffffffff_gg._hhhh_iiiiiii[
typ
]
except KeyError:
continue Diff9,12c9,12
< abcd_efgh, ijklmno =\
< AaaaBbbbbCccccc.DddddEeeeFffffffff_gg._hhhh_iiiiiii[
< typ
< ]
---
> abcd_efgh, ijklmno = AaaaBbbbbCccccc.DddddEeeeFffffffff_gg._hhhh_iiiiiii[
> typ
> ]
> Bug or by design? Other than refactoring all those indents, any workarounds? |
Black generally removes backslashes, which is by design. You can perhaps work around this by putting parentheses around the unpacking assignment, which will enable Black to put the variables on separate lines. Perhaps we should automatically insert these parens. |
There's some interesting stuff in here. First, some of the lines, the ones within the `# fmt: on`/`# fmt: off` blocks, could not be formatted by "black" due to psf/black#510. Second, I had to wrestle with "isort" quite a bit because it kept formatting the imports to be too long so I had to resort to the `# noqa: E501` solution. Last but not least, if an import is only used in a docstring, "flake8" doesn't seem to recognize it as used.
There's some interesting stuff in here. First, some of the lines, the ones within the `# fmt: on`/`# fmt: off` blocks, could not be formatted by "black" due to psf/black#510. Second, I had to wrestle with "isort" quite a bit because it kept formatting the imports to be too long so I had to resort to the `# noqa: E501` solution. Last but not least, if an import is only used in a docstring, "flake8" doesn't seem to recognize it as used.
@JelleZijlstra I think you meant to put parenthesis around the dot accessors result = "{} {} {}".format(
x,
y,
(
- z.and_then.something_very_deep.inside_the_complex.object_called_z.even_further
),
) result = "{} {} {}".format(
x,
y,
(
+ (z.and_then.something_very_deep.inside_the_complex.object_called_z).even_further
),
) After black result = "{} {} {}".format(
x,
y,
(
+ (
+ z.and_then.something_very_deep.inside_the_complex.object_called_z
+ ).even_further
),
) |
Two small examples that lead to lines longer than the configured maximum (see playground link below): a = (
a123456789.a123456789.a123456789.a123456789.a12345678()
)
a123456789.a123456789().a123456789().a123456789().a123456789() |
Operating system: Ubuntu 18.04
Python version: 3.6.5
Black version: 18.6b4 (via pip)
Does also happen on master: Yes
This might not be a bug, but then I'd like to get the (opinionated) explanation for this behavior.
Feeding this code into black:
Gives me this:
What bothers me is that the long dotted paths are kept on a single line that's way too long. The two examples are basically the same, I just tried the second thing with parentheses, as I got the impression – while skimming existing issues – that this might be a way to force wrapping the line to respect the line length limit.
How do I get black to wrap these lines within the limit, if possible at all?
Anyway: Thanks for an extremely nice utility :)
The text was updated successfully, but these errors were encountered: