Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ruff] Stabilize useless-if-else (RUF034) #15351

Merged
merged 2 commits into from
Jan 8, 2025
Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jan 8, 2025

Summary

Stabilize useless-if-else

I'm somewhat torn on the name:

  • most other rules specific to tenary expressions use if-expr -> useless-if-expr?
  • the expression itself isn't useless. It's just that the branching is useless

Clippy's name for the same rule is if_same_then_else which I like better because it doesn't suggest that it is useless. However, I fail to come up to address my first concern because if-expr-if-same-then-else sounds off but maybe it's fine?

Test Plan

There are no open issues for this rule.

The ecosystem changes look correct to me

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Jan 8, 2025
Copy link
Contributor

github-actions bot commented Jan 8, 2025

ruff-ecosystem results

Linter (stable)

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

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

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

+ superset/utils/decorators.py:158:9: RUF034 Useless `if`-`else` condition

pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)

+ pandas/tests/io/formats/style/test_style.py:936:26: RUF034 Useless `if`-`else` condition

pytest-dev/pytest (+1 -0 violations, +0 -0 fixes)

+ testing/_py/test_local.py:21:12: PYI006 Use `<` or `>=` for `sys.version_info` comparisons

astropy/astropy (+1 -0 violations, +0 -0 fixes)

+ astropy/cosmology/flrw/lambdacdm.py:267:15: PLR1716 [*] Contains chained boolean comparison that can be simplified

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
RUF034 2 2 0 0 0
PYI006 1 1 0 0 0
PLR1716 1 1 0 0 0

Linter (preview)

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

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

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

- airflow/decorators/condition.py:32:35: TC008 [*] Remove quotes from type alias
- airflow/decorators/condition.py:33:35: TC008 [*] Remove quotes from type alias

latchbio/latch (+0 -2 violations, +0 -0 fixes)

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

- src/latch/ldata/_transfer/upload.py:30:32: TC008 [*] Remove quotes from type alias
- src/latch/ldata/_transfer/upload.py:31:35: TC008 [*] Remove quotes from type alias

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TC008 4 0 4 0 0

@MichaReiser MichaReiser marked this pull request as ready for review January 8, 2025 13:32
@MichaReiser MichaReiser changed the title [RUF] Stabilize useless-if-else (RUF034) [ruff] Stabilize useless-if-else (RUF034) Jan 8, 2025
@MichaReiser MichaReiser added this to the v0.9 milestone Jan 8, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice! I kinda like the existing name 🤷

@MichaReiser MichaReiser force-pushed the micha/useless-if-else branch from c2917f2 to 7538099 Compare January 8, 2025 14:50
@MichaReiser MichaReiser merged commit 218831b into ruff-0.9 Jan 8, 2025
21 checks passed
@MichaReiser MichaReiser deleted the micha/useless-if-else branch January 8, 2025 14:56
@MichaReiser MichaReiser mentioned this pull request Jan 8, 2025
2 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants