Skip to content

Commit

Permalink
handle functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilinum committed Nov 27, 2022
1 parent 0b8ffe3 commit 82c8c9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mypy/partially_defined.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def visit_match_stmt(self, o: MatchStmt) -> None:
self.tracker.end_branch_statement()

def visit_func_def(self, o: FuncDef) -> None:
self.tracker.record_definition(o.name)
self.process_definition(o.name)
self.tracker.enter_scope()
super().visit_func_def(o)
self.tracker.exit_scope()
Expand Down
9 changes: 6 additions & 3 deletions test-data/unit/check-partially-defined.test
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ def f0(b: bool) -> None:

[case testUseBeforeDefClass]
# flags: --enable-error-code partially-defined --enable-error-code use-before-def
def f(x: A):
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
[case testGenerator]
# flags: --enable-error-code partially-defined
if int():
Expand Down

0 comments on commit 82c8c9b

Please sign in to comment.