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

PGH003 doesn't detect violation if another suppression on that line does include a code #5960

Closed
tylerlaprade opened this issue Jul 22, 2023 · 3 comments · Fixed by #5982
Closed

Comments

@tylerlaprade
Copy link
Contributor

The following code should be considered invalid because # pyright: ignore does not have a code. However, because # noqa has a code, the line doesn't get flagged.

secret_cache_item = self.cache_secrets_manager._get_cached_secret(self.secret_id)  # pyright: ignore # noqa[SLF001]

If I change it to

secret_cache_item = self.cache_secrets_manager._get_cached_secret(self.secret_id)  # pyright: ignore

then PGH003 does fire (as well as SLF001, of course.

The correct behavior is that only

secret_cache_item = self.cache_secrets_manager._get_cached_secret(self.secret_id) # pyright: ignore[reportPrivateUsage] # noqa[SLF001]

should be considered valid.

It's worth noting that # noqa is not recognized by Pyright, as it's a linter directing, not a type-checking one.

@charliermarsh
Copy link
Member

I think the issue here is that you have an invalid noqa code, so the PGH003 error is getting suppressed.

This works as expected:

secret_cache_item = self.cache_secrets_manager._get_cached_secret(self.secret_id)  # pyright: ignore # noqa: SLF001

@charliermarsh
Copy link
Member

# noqa[SLF001] is treated as equivalent to # noqa (blanket ignore). We can probably warn on that.

@tylerlaprade
Copy link
Contributor Author

Incidentally, I confirmed that both halves of this problem are fixed in the preview version:
image

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

Successfully merging a pull request may close this issue.

2 participants