You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PERF401 recommends to use list comprehensions even if it leads to nested list comprehensions. I would guess a lot of people agree that nested list comprehensions are a bad code practice, but I cannot find any sources, sadly.
I'm not sure how ruff internals work, but I guess it should not be extremely hard to figure out that there is a list comprehension inside of the block where the PERF401 is detected.
Other
ruff --version # 0.4.5
The text was updated successfully, but these errors were encountered:
I see the motivation but I feel like this is working as intended. The rule is looking for iterations that could be rewritten as comprehensions for micro-optimization purposes, and it's identifying one here. To take the other side of the argument, it would be surprising for PERF401 to sometimes trigger and sometimes not depending on the target expression. (Candidly, I don't find the real example to be much harder to read, but I recognize that's just subjective).
It's kind of a niche rule -- I'd recommend just disabling it if you're not in a situation that demands it, and aren't happy with the suggestions.
Description
PERF401 recommends to use list comprehensions even if it leads to nested list comprehensions. I would guess a lot of people agree that nested list comprehensions are a bad code practice, but I cannot find any sources, sadly.
Minimal example
When you run
ruff check --select PERF401 test.py
, you would get a recommendation to use a list comprehension.While minimal example does not look this bad, here is a real world example:
Real example
and wow, this is awful!
Possible solution
I'm not sure how ruff internals work, but I guess it should not be extremely hard to figure out that there is a list comprehension inside of the block where the PERF401 is detected.
Other
ruff --version # 0.4.5
The text was updated successfully, but these errors were encountered: