Skip to content
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

[used before def] correctly handle walrus operator #14646

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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