-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[pyupgrade
] Add fix safety section to docs (UP029
)
#17490
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
base: main
Are you sure you want to change the base?
[pyupgrade
] Add fix safety section to docs (UP029
)
#17490
Conversation
|
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 str then 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
Summary
add
fix safety
section 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.