quora / pyanalyze

A Python type checker
Apache License 2.0
333 stars 36 forks source link

pyanalyze doesn't propagate initialisation through conditions involving walrus #742

Closed hauntsaninja closed 6 months ago

hauntsaninja commented 6 months ago
import os

def info(arg: str):
    if arg and (var := os.environ.get("ENV")):
        raise RuntimeError(f"{arg}: {var}")

gives me:

λ pyanalyze b.py

var may be used uninitialized (code: possibly_undefined_name)
In b.py at line 6
   3: 
   4: def info(arg: str):
   5:     if arg and (var := os.environ.get("ENV")):
   6:         raise RuntimeError(f"{arg}: {var}")
                                           ^
JelleZijlstra commented 6 months ago

Duplicate of #597

Thanks for these issues, I'll try to find some time to work on them