ruff: RET508 potential false positive after elif
This is with ruff==0.0.155
I tried to drill it down to a simpler example but it did not happen there. Can you try to run ruff with RET508
enabled on this file, like
ruff rotkehlchen/tests/api/test_async.py
It’s returning
rotkehlchen/tests/api/test_async.py:75:13: RET508 Unnecessary `else` after `break` statement
rotkehlchen/tests/api/test_async.py:137:9: RET508 Unnecessary `else` after `break` statement
Which I am confused how it makes sense.
If we remove the else and put the Assertion (or any other code) after the if/elif
the resulting code won’t be the same.
I got similar questionable results with the other RET codes btw.
Also a question on pyproject toml. I have ended up with somethine like:
select = ["E", "F", "W", "C", "N", "B", "T", "UP", "YTT", "C4", "T10", "T201"]
Isn’t T
a superset of T201
and T210
? So I can omit those? Same for C4
and C
?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (15 by maintainers)
Commits related to this issue
- Avoid unnecessary-else violations in `elif` branches (#2881) Long-time source of confusion -- two reports over 1800 issues apart. Closes #1035. Closes #2879. — committed to astral-sh/ruff by charliermarsh a year ago
You don’t need else after a control flow statement. That’s
return
,yield
,break
, orcontinue
. Remove the “el” in front of the elif.And yeah, your configuration is equivalent to: