You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PEP 572: Type not narrowed correctly in assignment #7316
from typing import Optional
class C:
def foo(self):
pass
def good(b: Optional[C]) -> None:
a = b
if a:
a.foo()
def bad(b: Optional[C]) -> None:
if a := b:
a.foo() # E: Item "None" of "Optional[C]" has no attribute "foo"
is the flagship example taken from Python 3.8 What's New, and is actually the prime use case for assignment expressions in general. Raising priority to high.
Activity
ilevkivskyi commentedon Nov 22, 2019
This is actually pretty important to support, this example:
is the flagship example taken from Python 3.8 What's New, and is actually the prime use case for assignment expressions in general. Raising priority to high.
Narrow types for walrus assignment in if statements
Narrow types for walrus assignment in if statements (#8258)
📇 Add type hints to all the code