ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Add rule to use sys.exit() instead of exit()

Open JonathanPlasse opened this issue 2 years ago • 3 comments

exit() is not a built-in function and is only defined if the site module is imported during Python's initialization (which, for example, can be disabled with -S option passed to the interpreter). You should use sys.exit() instead:

    sys.exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))

_Originally posted by @jack1142 in https://github.com/charliermarsh/ruff/pull/776#

Fixed, thanks. (Ruff should have a rule for this!)

Originally posted by @andersk in https://github.com/charliermarsh/ruff/pull/776#discussion_r1024474885


I would like to implement it. In which rule group would this be added?

JonathanPlasse avatar Nov 17 '22 13:11 JonathanPlasse

Awesome! This should go in the RUF group since it's new / custom to Ruff.

charliermarsh avatar Nov 17 '22 15:11 charliermarsh

How can I check if exit() has not been overridden? Which, in this case, should not trigger an error.

JonathanPlasse avatar Nov 18 '22 18:11 JonathanPlasse

We have to resolve that for https://github.com/charliermarsh/ruff/issues/780. We need to check if the BindingKind on the identifier is still BindingKind::Builtin. You could omit it for now if you'd rather wait until it's solved for #780.

charliermarsh avatar Nov 18 '22 18:11 charliermarsh