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: String in return annotation #2699

Closed
intgr opened this issue Dec 15, 2021 · 3 comments · Fixed by #2990
Closed

Line too long: String in return annotation #2699

intgr opened this issue Dec 15, 2021 · 3 comments · Fixed by #2990
Labels
F: linetoolong Black makes our lines too long F: strings Related to our handling of strings T: bug Something isn't working

Comments

@intgr
Copy link

intgr commented Dec 15, 2021

To Reproduce

Given input:

class ThisIsTrulyUnreasonablyExtremelyLongClassName:
    pass


def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
    pass

Black does not split the long type hint of the function return type

Even if I explicitly attempt to split the string:

def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | " \
                    "list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
    pass

then Black collapses it back together :(

def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | " "list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
    pass

Workaround

Only by parenthesizing the type hint I can convince Black to keep it reasonable.

def frobnicate() -> (
    "ThisIsTrulyUnreasonablyExtremelyLongClassName | "
    "list[ThisIsTrulyUnreasonablyExtremelyLongClassName]"
):
    pass

Environment

  • Black's version: 21.12b0
  • OS and Python version: macOS, Python 3.10.1
@intgr intgr added the T: bug Something isn't working label Dec 15, 2021
@ichard26 ichard26 added F: linetoolong Black makes our lines too long F: strings Related to our handling of strings labels Dec 16, 2021
@ichard26
Copy link
Collaborator

Can confirm this exists on main as of commit e9f520c even with experimental string processing enabled. Thank you for the report!

@JelleZijlstra JelleZijlstra changed the title Quoted type hints can exceed line length limits Line too long: String in return annotation Jan 29, 2022
jpy-git added a commit to jpy-git/black that referenced this issue Apr 6, 2022
@jpy-git jpy-git mentioned this issue Apr 6, 2022
3 tasks
@ichard26 ichard26 linked a pull request Apr 9, 2022 that will close this issue
3 tasks
@jakkdl
Copy link
Contributor

jakkdl commented Oct 5, 2023

This should be reopened, or open a new issue, as it didn't get fixed by #2990 other than the specific case of having no parameters. See the test case added in #3916: https://github.com/jakkdl/black/blob/be48f7bee25efccdf6957a3c37dcce8a82301819/tests/data/preview/return_annotation_brackets_string.py

@JelleZijlstra
Copy link
Collaborator

Could you open a new issue?

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: strings Related to our handling of strings T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants