[pyupgrade] Add fix safety section to docs (UP029)#17490
[pyupgrade] Add fix safety section to docs (UP029)#17490dylwil3 merged 4 commits intoastral-sh:mainfrom
pyupgrade] Add fix safety section to docs (UP029)#17490Conversation
|
|
I have two example one should look into :-) The first one is the case where we import a builtin with an alias, e.g., For the second, let's suppose that we do something like: # Original code
def str(x):
return f"Custom: {x}"
# somewhere in the code
from builtins import str
result = str(1) # Uses Python's builtin strthen the rules will correct that as def str(x):
return f"Custom: {x}"
result = str(1)which is a change of behaviour. |
The first point should be skipped, but the second one does affect the original behavior. Thank you very much! |
pyupgrade] Add fix safety section to docs (UP029)
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of #15584 This adds a `Fix safety` section to [unnecessary-future-import (UP010)](https://docs.astral.sh/ruff/rules/unnecessary-future-import/#unnecessary-future-import-up010) The unsafety is determined here: https://github.com/astral-sh/ruff/blob/d9266284df170cd70908761b5d5ae45b25523a40/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs#L128-L132 Unsafe code example: [playground](https://play.ruff.rs/c07d8c41-9ab8-4b86-805b-8cf482d450d9) ```py from __future__ import (print_function,# ... __annotations__) # ... ``` Edit: It looks like there was already a PR for this, #17490, but I missed it since they said `UP029` instead of `UP010` :/ ## Test Plan <!-- How was it tested? --> N/A, no tests/functionality affected
dylwil3
left a comment
There was a problem hiding this comment.
Thanks @Kalmaegi and @VascoSch92 !
## Summary Add `fix safety` section to `UP029: unnecessary_builtin_import.rs`, for astral-sh#15584
Summary
add
fix safetysection toUP029: unnecessary_builtin_import.rs, for #15584I conducted some tests and found that the only side effect should be the removal of inline comments along with the code. However, during the deletion process, comments placed above the code are preserved. I'm not sure if this behavior needs to be explicitly described.