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

[flake8-comprehensions] Set comprehensions not a violation for sum in unnecessary-comprehension-in-call (C419) #12691

Merged
merged 3 commits into from
Aug 6, 2024

Conversation

dylwil3
Copy link
Contributor

@dylwil3 dylwil3 commented Aug 5, 2024

Summary

Removes set comprehension as a violation for sum when checking C419, because set comprehension may de-duplicate entries in a generator, thereby modifying the value of the sum.

Closes #12690.

Copy link
Contributor

github-actions bot commented Aug 5, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+1 -1 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

apache/airflow (+1 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select ALL

- tests/api_connexion/endpoints/test_event_log_endpoint.py:367:24: C419 Unnecessary list comprehension
+ tests/api_connexion/endpoints/test_event_log_endpoint.py:367:24: C419 Unnecessary set comprehension

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
C419 2 1 1 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -1 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

apache/airflow (+1 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- tests/api_connexion/endpoints/test_event_log_endpoint.py:367:24: C419 Unnecessary list comprehension
+ tests/api_connexion/endpoints/test_event_log_endpoint.py:367:24: C419 Unnecessary set comprehension

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
C419 2 1 1 0 0

format!("Unnecessary list comprehension")
match self.comprehension_kind {
ComprehensionKind::List => format!("Unnecessary list comprehension"),
ComprehensionKind::Set => format!("Unnecessary set comprehension"),
Copy link
Member

Choose a reason for hiding this comment

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

I changed this to a manual match rather than using Display for the (bad) reason that we use the first format! call here to show the example error message in the docs, and "Unnecessary list comprehension" is better than "Unnecessary {} comprehension".

@charliermarsh charliermarsh added the bug Something isn't working label Aug 6, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) August 6, 2024 02:26
@charliermarsh charliermarsh merged commit 52630a1 into astral-sh:main Aug 6, 2024
19 checks passed
@dylwil3 dylwil3 deleted the c419-set-comprehension branch August 6, 2024 02:49
dylwil3 added a commit to dylwil3/ruff that referenced this pull request Aug 7, 2024
…` in `unnecessary-comprehension-in-call` (`C419`) (astral-sh#12691)

## Summary

Removes set comprehension as a violation for `sum` when checking `C419`,
because set comprehension may de-duplicate entries in a generator,
thereby modifying the value of the sum.

Closes astral-sh#12690.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C419 should not flag set comprehensions for sum
2 participants