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

Preview style wraps long unbreakable strings differently based on whether the LHS has an annotation #3954

Open
yilei opened this issue Oct 18, 2023 · 1 comment

Comments

@yilei
Copy link
Contributor

yilei commented Oct 18, 2023

Black v23.10.0

Playground link

Options

--line-length=88
--safe
--preview

Input

class A:
    attr1: str = 'this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long'
    attr2 = 'this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long'

Output

class A:
    attr1: str = (
        "this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long"
    )
    attr2 = "this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long"

Expected

class A:
    attr1: str = "this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long"
    attr2 = "this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long_this_is_very_very_long"

Since the string wrapped in parens still can't fit in the line-length, Black won't wrap.

Did a git-bisect and this behavior was introduced in #3899, and it doesn't seem to be an intentional change from that PR.

@jakkdl
Copy link
Contributor

jakkdl commented Dec 5, 2023

Heya, author of #3899 here.

The behaviour makes sense to me, since the type could also be long.

class A:
    attr1: my_long_very_custom_type_bla_bla_bla = "111111111111111111111111111111111111111111111111111111"

makes sense to me to break, even if the string can't be fit inside the line length.

Can confirm I didn't explicitly think about this case - but am not surprised that this behavior got changed since it did mess around with line-wrapping and type hints. But I'm not really against this behavior getting reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants