-
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
Better documentation of unsafe fixes #8482
Comments
Yeah that's a nice idea. We've started doing this in some places via a "Known problems" section. I'll try to get the remaining rules covered next week. (If helpful, you can also set |
There's some overlap in the ideas from my comment in #8075 (comment) so I'll copy here as well:
|
Please let us know if there's a rule with an unsafe fix that is not explained in the documentation, we can start tracking adding documentation at least. |
Rule with unsafe fix that caused me to open this issue was C416. I'll post on here as I notice others :-) |
(Adding docs for those rules now.) |
Done in #8918. |
A few more unsafe fixes that could use docs:
|
I think UP028 might be safe except in very rare circumstances. I'm trying to come up with an example in which the modification could lead to a breaking change. |
Relates to astral-sh#8482
Sure, when the generator is being sent values (and discarding them) but it's yielding values from an iterator it is an unsafe fix. E.g. this code works fine: def foo():
for x in range(10):
yield x
gen_foo = foo()
next(gen_foo)
gen_foo.send(10) But UP028 fixes is to this: def foo():
yield from range(10)
gen_foo = foo()
next(gen_foo)
gen_foo.send(10) Which throws the exception:
Now, there probably should be some rule about sending to a generator that doesn't read the values. But I'm sure someone has some code somewhere that does this. |
@notatallshaw-gts - thank you! |
Okay, all of the enumerated rules in the issue have either been documented or are being prompted to safe in v0.2.0. Going forward, I'm also ensuring that all unsafe fixes are included in the rule documentation for new fixes and rules. |
…arameterize-test-cases` (#9678) See: #8482 (comment).
## Summary This seems safe to me. See #8482 (comment). ## Test Plan `cargo test`
#9679) ## Summary Prompted by #8482 (comment). The rename is only unsafe when the symbol is exported, so we can narrow the conditions.
…arameterize-test-cases` (#9678) See: #8482 (comment).
## Summary This seems safe to me. See #8482 (comment). ## Test Plan `cargo test`
#9679) ## Summary Prompted by #8482 (comment). The rename is only unsafe when the symbol is exported, so we can narrow the conditions.
#9679) ## Summary Prompted by #8482 (comment). The rename is only unsafe when the symbol is exported, so we can narrow the conditions.
#9679) ## Summary Prompted by #8482 (comment). The rename is only unsafe when the symbol is exported, so we can narrow the conditions.
#9679) ## Summary Prompted by #8482 (comment). The rename is only unsafe when the symbol is exported, so we can narrow the conditions.
I don't know if it's fine to comment here or if I should open a new issue, but SIM117's docs don't have a "Fix safety" section, even though the fix for it seems to only get activated when enabling unsafe fixes. So it would be good if such a section was added. |
It would be nice if it was easier to figure out what checks have unsafe fixes, e.g. maybe there could be a different icon next to the rules in https://docs.astral.sh/ruff/rules/
It would also be nice if the per-rule documentation also mentioned why the fix is unsafe. E.g. for https://docs.astral.sh/ruff/rules/unnecessary-comprehension/ I'm left guessing, is it because ruff will apply the fix even when
dict
is bound to something else (edit: maybe because cases where we unpack we now lose errors)?(For some user context: on a lot of our code, we only run ruff for autofixes and do not report errors for unfixable lints. Autofixing is a killer feature)
The text was updated successfully, but these errors were encountered: