8000 [`flake8-2020`] Fix diagnostic message for `!=` comparisons (`YTT201`) by charliermarsh · Pull Request #18293 · astral-sh/ruff · GitHub
[go: up one dir, main page]

Skip to content

[flake8-2020] Fix diagnostic message for != comparisons (YTT201) #18293

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

Conversation

charliermarsh
Copy link
Member
@charliermarsh charliermarsh commented May 25, 2025

Summary

Closes #18292.

Copy link
Contributor
github-actions bot commented May 25, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member
@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I get chatgpt to address my comments?

@@ -88,12 +88,23 @@ impl Violation for SysVersionCmpStr3 {
/// - [Python documentation: `sys.version`](https://docs.python.org/3/library/sys.html#sys.version)
/// - [Python documentation: `sys.version_info`](https://docs.python.org/3/library/sys.html#sys.version_info)
#[derive(ViolationMetadata)]
pub(crate) struct SysVersionInfo0Eq3;
pub(crate) struct SysVersionInfo0Eq3 {
op: CmpOp,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a boolean saying if it's == or !=. Took me a while to realise that the rule doesn't support other compare operators

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@@ -246,7 +257,7 @@ pub(crate) fn compare(checker: &Checker, left: &Expr, ops: &[CmpOp], comparators
{
if *n == 3 && checker.enabled(Rule::SysVersionInfo0Eq3) {
checker.report_diagnostic(Diagnostic::new(
SysVersionInfo0Eq3,
SysVersionInfo0Eq3 { op: ops[0] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use operator @ in the let arm instead of retrieving it form ops[0]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@MichaReiser MichaReiser added the diagnostics Related to reporting of diagnostics. label May 25, 2025
@charliermarsh
Copy link
Member Author

You can't, it doesn't support any kind of iteration.

@charliermarsh charliermarsh merged commit 14c3755 into main May 25, 2025
34 checks passed
@charliermarsh charliermarsh deleted the codex/fix-misleading-diagnostic-for-!=-expressions-in-ytt201 branch May 25, 2025 17:16
@dhruvmanila dhruvmanila changed the title Fix YTT201 for '!=' comparisons [flake8-2020] Fix diagnostic message for != comparisons (YTT201) May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codex diagnostics Related to reporting of diagnostics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

YTT201 diagnostic is wrong when the expression uses !=
2 participants
0