-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[use before def] handle class and function definitions #14203
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,17 @@ def f0(b: bool) -> None: | |
fn = lambda: 2 | ||
y = fn # E: Name "fn" may be undefined | ||
|
||
[case testUseBeforeDefClass] | ||
# flags: --enable-error-code partially-defined --enable-error-code use-before-def | ||
def f(x: A): # No error here. | ||
pass | ||
y = A() # E: Name "A" is used before definition | ||
class A: pass | ||
|
||
[case testUseBeforeDefFunc] | ||
# flags: --enable-error-code partially-defined --enable-error-code use-before-def | ||
foo() # E: Name "foo" is used before definition | ||
def foo(): pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case, could you please add test for classes within functions and vice versa? Also maybe add a test where a variable is defined in a class and then is being red outside of class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added tests. |
||
[case testGenerator] | ||
# flags: --enable-error-code partially-defined | ||
if int(): | ||
|
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.
Why do we have
enter_scope()
for functions but not for classes? A variable defined in a class body will not be visible outside (as a variable, will still be available as an attribute of course)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.
Yep, good point. Added enter and exit scope calls (with tests that were failing before)