-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add convert exit() to sys.exit() rule #816
Add convert exit() to sys.exit() rule #816
Conversation
95b3d0c
to
e3cbc0c
Compare
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I meant! Oh, very nice.
f0a343f
to
6f411cb
Compare
@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
6f411cb
to
8493e42
Compare
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.) |
import sys
import sys as sys2
does not workimport sys.exit
from sys import exit as exit2
sys
. Is there an example of how to add an import while keeping it sorted ifI
is 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?