-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
false positive for PERF203 with try-except-continue-else #11602
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Looking at the code, the reason why the above is flagged and wasn't addressed by #6535 is that the rule only checks for ruff/crates/ruff_linter/src/rules/perflint/rules/try_except_in_loop.rs Lines 106 to 108 in f9d8189
The rule only applies to Python 310 or older because
|
I still think the rule should flag the above pattern because whether there's a better way to write the above loop depends on the for c in s:
name = unicodedata.name("a", None)
if name is None:
continue
else:
f.write(c) which eliminates the need for try |
I don't think ruff understand because ruff still flag this, and I don't think there is a better way to write this: import requests
def check_url_live(urls: str):
for url in urls:
try:
requests.get(url, timeout=5)
except ConnectionRefusedError:
continue
else:
print(url) |
if you think it should flag this, then there is another problem: it doesn't flag this: import unicodedata
def check_url_live(s: str):
for c in s:
try:
unicodedata.name(c)
except ValueError:
continue
print(c) |
Yeah, there's probably not a better way to write this and using a noqa comment here seems appropriate.
I would have to double check the upstream rule to understand if this is a bug but the rule currently only flags cases where the |
Going through the history. Ignoring multi-statement loops is intentional, see #6145 Using noqa comment seems the right solution to deal with cases where using |
I think we are actully talking about 2 topics here... Ignoring multi-statement loops is fine to me, and this issue is not about it should or should not ignore multi-statement loops. the "false positive" is, it didn't ignore single |
ruff 0.6.5 raise false positive for try-except in a look with
else
previous issue: #6535
this looks like #6535 but it still exists then targeting py38
https://play.ruff.rs/eadb6e43-5f78-4bcd-93f3-2d409bdbf4c8
The text was updated successfully, but these errors were encountered: