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

SystemExit and sys.exit behavior overlap #1786

Closed
thecnoNSMB opened this issue Dec 18, 2020 · 2 comments
Closed

SystemExit and sys.exit behavior overlap #1786

thecnoNSMB opened this issue Dec 18, 2020 · 2 comments
Labels
rule request Adding a new rule

Comments

@thecnoNSMB
Copy link

Rule request

raise SystemExit(arg) and sys.exit(arg) are identical in behavior, one should be favored over the other for consistency.

Reasoning

I don't know which of the two would be preferable for this linter (I suspect sys.exit(arg), but raise SystemExit(arg) doesn't require any imports), but several other contexts where multiple forms are valid have a rule enforcing one form as the standard (such as single vs double quotes, or string formatting methods), and I figure the same logic should apply here.

@thecnoNSMB thecnoNSMB added the rule request Adding a new rule label Dec 18, 2020
@thecnoNSMB
Copy link
Author

thecnoNSMB commented Dec 18, 2020

quit(arg) and exit(arg) should also be prohibited under this rule, as those are from the site module and are only intended to be used for the REPL; as such, they may not be loaded at all when a script runs.

@orsinium
Copy link
Collaborator

orsinium commented Jan 4, 2021

I suspect sys.exit(arg), but raise SystemExit(arg) doesn't require any imports

Yes, I am for sys.exit.

  1. Importing of sys is incredibly fast, I'd even say free:

    import sys
    sys.__loader__  # _frozen_importlib.BuiltinImporter
    sys.meta_path.index(sys.__loader__)  # 0
  2. It should be clear that this statement isn't an exception that can be caught somewhere up in the stack but an uncompromised exit without turning back.

quit(arg) and exit(arg) should also be prohibited under this rule

WPS already has this one:

WPS421 | Found wrong function call: exit

However, I guess it should be more verbose like in pylint:

R1722 | Consider using sys.exit()

sobolevn added a commit that referenced this issue Dec 22, 2024
sobolevn added a commit that referenced this issue Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

2 participants