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

Black puts "pyright: ignore" comments on the wrong line #3946

Open
RobinFrcd opened this issue Oct 16, 2023 · 3 comments
Open

Black puts "pyright: ignore" comments on the wrong line #3946

RobinFrcd opened this issue Oct 16, 2023 · 3 comments
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working

Comments

@RobinFrcd
Copy link

Hi,
I've switched to VS code and pyright recently, and I realized black is breaking a lot of # pyright: ignore comments.

Input (both are valid for pyright):

asm_client: SecretsManagerClient = boto3.client("secretsmanager") # pyright: ignore[reportUnknownMemberType]
asm_client: SecretsManagerClient = boto3.client( # pyright: ignore[reportUnknownMemberType]
    "secretsmanager"
)  

Output:

asm_client: SecretsManagerClient = boto3.client(
    "secretsmanager"
)  # pyright: ignore[reportUnknownMemberType]
asm_client: SecretsManagerClient = boto3.client(
    "secretsmanager"
)  # pyright: ignore[reportUnknownMemberType]

Is there a way to stick the pyright comment to the original line ?

I'm using:

black, 23.9.1 (compiled: yes)
Python (CPython) 3.11.6

Thanks

@RobinFrcd RobinFrcd added the T: bug Something isn't working label Oct 16, 2023
@JelleZijlstra JelleZijlstra changed the title Black breaks pyright compatibility Black puts "pyright: ignore" comments on the wrong line Oct 16, 2023
@JelleZijlstra
Copy link
Collaborator

See also #3661.

I think this is inherently impossible to solve in all cases, because if Black splits a line, it has no way to know which part of the line the ignore comment should apply to. However, we could probably come up with a better heuristic, like putting the comment on the first rather than the last line.

@JelleZijlstra JelleZijlstra added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label Oct 16, 2023
@psf psf deleted a comment Oct 28, 2023
@henriholopainen
Copy link
Contributor

When/if this gets merged, one option would be:

asm_client: SecretsManagerClient = boto3.client("secretsmanager")  # fmt: skip; pyright: ignore[reportUnknownMemberType]

@JelleZijlstra
Copy link
Collaborator

Pyright doesn't support that syntax though. (Maybe it should, but that's not a question for this tracker.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants