[pylint] add fix safety section (PLR1722)#17826
Conversation
|
|
I think the fix is always unsafe... |
|
@VascoSch92 Thanks for the input! I’m new to the project—could you elaborate a bit? I was referencing this: |
|
Fix availability is separate from fix safety. In some cases we might offer a diagnostic without a fix at all, regardless of safety. For this rule, that can happen if we fail to generate the new import edit, for example. There's not really a centralized safety marker, you generally just have to search for Thanks for working on this! |
ntBre
left a comment
There was a problem hiding this comment.
Related to my other comment, this is more of a description of the fix's availability rather than its safety. It's not immediately clear to me why this fix is unsafe, which is one of the challenging parts of these cases. You may need to look back at the original PR adding the rule for more discussion.
|
The rule description says “ $ cat >plr1722_1.py <<'# EOF'
exit(2)
# EOF
$ python -S plr1722_1.py; echo $?
Traceback (most recent call last):
File "plr1722_1.py", line 1, in <module>
exit()
^^^^
NameError: name 'exit' is not defined
1
$ ruff --isolated check plr1722_1.py --select PLR1722 --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).
$ python -S plr1722_1.py; echo $?
2Another difference between $ cat >plr1722_2.py <<'# EOF'
exit(())
# EOF
$ cat >plr1722_3.py <<'# EOF'
exit((2,))
# EOF
$ python plr1722_2.py; echo $?
()
1
$ python plr1722_3.py; echo $?
(2,)
1
$ ruff --isolated check plr1722_{2,3}.py --select PLR1722 --unsafe-fixes --fix
Found 2 errors (2 fixed, 0 remaining).
$ python plr1722_2.py; echo $?
0
$ python plr1722_3.py; echo $?
2 |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! This looks good to me.
parent: astral-sh#15584 fix introduced at: astral-sh#816
parent: #15584
fix introduced at: #816