Add convert exit() to sys.exit() rule#816
Add convert exit() to sys.exit() rule#816charliermarsh merged 6 commits intoastral-sh:mainfrom JonathanPlasse:add-sys-exit-rule
Conversation
Hmm, no, we don't do that anywhere yet. Let's try for that later, as it would require fixes with multiple edits that change multiple parts of the tree.
Yeah, yeah you have to iterate over every scope in reverse, like: for scope_index in self.scope_stack.iter().rev() {
let scope = &mut self.scopes[*scope_index];
...
}We might want to add a |
Let's open an issue once this PR is merged.
I added |
|
@JonathanPlasse - I think your code is actually right! But the test case is a bit off. Right now, you have this: ...
def main():
exit(6) # Is not detected
...
def exit(e):
print(e)
...So, you're re-defining I think you'll need to split into a few different test files to evaluate all of those cases. |
| _ => None, | ||
| }) | ||
| }) | ||
| } |
There was a problem hiding this comment.
Probably a bit hard to get right since also needs to take aliases into account... but could be useful beyond this rule if robust.
There was a problem hiding this comment.
Do you mean alias as in from a import b as alias or import a as alias?
If yes, it already does.
There was a problem hiding this comment.
Yeah, that's what I meant! Oh, very nice.
|
@JonathanPlasse - Feel free to mark as "ready for review" when you're happy with this! |
--fix does not import sys if needed exit inside functions is not detected
exit inside functions is still not detected
|
I am ready for review :) |
|
Is it possible to make a |
|
Is it normal that I have to specify |
|
Great! Will review tonight! @JonathanPlasse - No, |
|
(Fixed in #838.) |
parent: astral-sh#15584 fix introduced at: astral-sh#816
import sysimport sys as sys2does not workimport sys.exitfrom sys import exit as exit2sys. Is there an example of how to add an import while keeping it sorted ifIis selected?exit()is not detected inside functions. What did I do wrong? Is itcurrent_scope()that is not enough? Do I need to iterate over every scope?