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

string_processing: makes it impossible to use a comment to ignore a static type violation #3802

Open
tylerlaprade opened this issue Jul 19, 2023 · 1 comment
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings T: bug Something isn't working

Comments

@tylerlaprade
Copy link

tylerlaprade commented Jul 19, 2023

Describe the bug

Black's --preview mode makes it impossible to suppress a type error in a string with a long comment.

To Reproduce

For example, take this code:

    def __str__(self):
        return "foo bar baz qux" # pyright: ignore[reportGeneralTypeIssues] -- This is some special Django magic that we can't easily tell Pyright about

And run it with these arguments:

$ black --preview

The resulting error is:

Unnecessary "# pyright: ignore" rule: "reportGeneralTypeIssues" (Pylance)

    def __str__(self):
        return (  # pyright: ignore[reportGeneralTypeIssues] -- This is some special Django magic that we can't easily tell Pyright about
            "foo bar baz qux"
        )

If I move the comment to the middle line, black moves it back up to the top.

Expected behavior

Even if black breaks my comment in some cases, there should be at least one possible place for me to leave the comment that will suppress my type error without black moving it.

Environment

  • Black's version: 23.7.0
  • OS and Python version: MacOS, 3.11

Additional context

This also occurs if the comment starts on the line with the violation

@tylerlaprade tylerlaprade added the T: bug Something isn't working label Jul 19, 2023
@hauntsaninja hauntsaninja added the C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. label Jul 19, 2023
@JelleZijlstra JelleZijlstra added the F: strings Related to our handling of strings label Nov 21, 2023
@JelleZijlstra
Copy link
Collaborator

This is related to experimental string processing. Noting this here because @hauntsaninja in #4042 wasn't sure which part of the preview style was causing this issue. I verified it's string processing by editing Black to turn on preview style except string processing.

@JelleZijlstra JelleZijlstra changed the title --preview makes it impossible to use a comment to ignore a static type violation string_processing: makes it impossible to use a comment to ignore a static type violation Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants