Skip to content

Commit

Permalink
[used before def] correctly handle walrus operator (python#14646)
Browse files Browse the repository at this point in the history
Fixes python#14626.

I believe changing the way that we analyze call expression makes sense
(first, we analyze the callee, then we analyze the arguments).
  • Loading branch information
ilinum committed Feb 8, 2023
1 parent bc18017 commit 4e2a113
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/traverser.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ def visit_yield_expr(self, o: YieldExpr) -> None:
o.expr.accept(self)

def visit_call_expr(self, o: CallExpr) -> None:
o.callee.accept(self)
for a in o.args:
a.accept(self)
o.callee.accept(self)
if o.analyzed:
o.analyzed.accept(self)

Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ def foo() -> None:
[x := x + y for y in [1, 2, 3]]
[builtins fixtures/dict.pyi]

[case testWalrusUsedBeforeDef]
# flags: --python-version 3.8
class C:
def f(self, c: 'C') -> None: pass

(x := C()).f(y) # E: Cannot determine type of "y" # E: Name "y" is used before definition
(y := C()).f(y)

[case testOverloadWithPositionalOnlySelf]
# flags: --python-version 3.8
from typing import overload, Optional
Expand Down

0 comments on commit 4e2a113

Please sign in to comment.