Skip to content
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

PLR1722 should convert a code keyword argument to a positional argument #16396

Open
dscorbett opened this issue Feb 26, 2025 · 2 comments · May be fixed by #16424
Open

PLR1722 should convert a code keyword argument to a positional argument #16396

dscorbett opened this issue Feb 26, 2025 · 2 comments · May be fixed by #16424
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome

Comments

@dscorbett
Copy link

Summary

exit and quit each have one positional-or-keyword parameter: code. sys.exit has one positional-only parameter. sys-exit-alias (PLR1722) should convert a code keyword argument to a positional argument to avoid changing behavior.

$ cat >plr1722.py <<'# EOF'
exit(code=2)
# EOF

$ python plr1722.py; echo $?
2

$ ruff --isolated check --select PLR1722 plr1722.py --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).

$ python plr1722.py; echo $?
Traceback (most recent call last):
  File "plr1722.py", line 2, in <module>
    sys.exit(code=2)
TypeError: sys.exit() takes no keyword arguments
1

Version

ruff 0.9.7 (54fccb3 2025-02-20)

@AlexWaygood AlexWaygood added bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome labels Feb 26, 2025
@VascoSch92
Copy link
Contributor

VascoSch92 commented Feb 26, 2025

moreover

code = {"code": 2}
exit(**code)

is fixed as

import sys

code = {"code": 2}
sys.exit(**code)

which leads to the same error.

@VascoSch92
Copy link
Contributor

Actually, I can give a try. It should be fast ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants