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

Incorrect "possibly_undefined_name" with walrus operator #597

Closed
JelleZijlstra opened this issue Feb 22, 2023 · 0 comments · Fixed by #749
Closed

Incorrect "possibly_undefined_name" with walrus operator #597

JelleZijlstra opened this issue Feb 22, 2023 · 0 comments · Fixed by #749

Comments

@JelleZijlstra
Copy link
Contributor

% cat ~/Desktop/walrus.py 
from typing_extensions import assert_type


def f() -> int:
    return 3


def g(cond: bool) -> None:
    if cond and (x := f()):
        assert_type(x, int)
% python -m pyanalyze ~/Desktop/walrus.py  -e possibly_undefined_name

x may be used uninitialized (code: possibly_undefined_name)
In /Users/jelle/Desktop/walrus.py at line 10
   7: 
   8: def g(cond: bool) -> None:
   9:     if cond and (x := f()):
  10:         assert_type(x, int)
                          ^

Type is Union[Any[error], int] (expected int) (code: inference_failure)
In /Users/jelle/Desktop/walrus.py at line 10
   7: 
   8: def g(cond: bool) -> None:
   9:     if cond and (x := f()):
  10:         assert_type(x, int)
              ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant