-
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
Strange fix behavior for UP006/NonPEP585Annotation fixer since ruff 0.8.5 #15245
Comments
Thanks for these. At least for Example 1, I think Ruff is avoiding introducing a new import since |
This is super helpful, thank you! And apologies for the strange behavior here. I think the two main things going on are: First, I wonder if the autofix should first try to remove the bad import so that there's less likely to be a name collision when adding the new one. Second, we can probably be cleverer in the implementation of the helper function that gets imports, and try to search for the most concise import to use if we have both, say, |
For Example 1, Ruff 0.8.4 is doing what I would expect, and 0.8.5 does not. $ ruff --isolated check --target-version=py310 --select=UP006,UP035,F401 --preview --fix --unsafe-fixes test.py
Well, in all of the above cases, Ruff 0.8.4 is doing what I would expect, I just didn't realize why there was a difference with I think the fixer should not care whatsoever about an existing import of Consider this related example: import typing
from typing_extensions import Final
a: Final[str] = typing.cast(str, 123) It simply replaces It is my opinion that the fixer should treat additions of |
Thanks. I reverted the change and published a bugfix release 0.8.6 |
Thanks a lot!! |
Thanks for the fix in #15250 @MichaReiser I resolved these already, but linking the relevant PRs from |
I am reporting strange behaviors since ruff 0.8.5. I have not tried ruff from master branch.
Example 1
Example file
test.py
:Command:
File content after ruff 0.8.4 applied:
(doesn't fix
Callable
because it's marked as py310+)File content after ruff 0.8.5 applied:
(weird!! explicit reference to
collections.abc.Callable
)Example 2
Example file
test.py
:Command:
File content after ruff 0.8.4 applied:
File content after ruff 0.8.5 applied:
Same, but with this additional output:
This was referenced in Errors for attempted autofixes visible to users even without passing
--fix
and for noqa lines #15229but the description of the "fix" for that issue seems to imply that the error messages themselves are the only problem, which I think is not right.
Ruff should be able to replace
from typing import Callable
.Example 3
Example file
test.py
:Command: (note
py38
here, unlike all other examples)File content after ruff 0.8.4 applied:
No change, no errors
File content after ruff 0.8.5 applied:
No change, but with this additional output (why does it fail to perform the fixes here??):
Example 4
Example file
test.py
:Command:
File content after ruff 0.8.4 applied:
File content after ruff 0.8.5 applied:
(weirdest one yet!!! changes only one of the two imports, and then proceeds to not even use the imports!!)
The text was updated successfully, but these errors were encountered: