-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-strict-optionaltopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
The errors generated for the following code are invalid (when using --strict-optional
):
from typing import Optional, Callable
def f1(key: Callable[[], str]) -> None: ...
def f2(key: object) -> None: ...
def g(b: Optional[str]) -> None:
if b:
f1(lambda: b.upper()) # Item "None" of "Optional[str]" has no attribute "upper"
z: Callable[[], str] = lambda: b.upper() # Item "None" of "Optional[str]" has no attribute "upper"
f2(lambda: b.upper()) # No error
lambda: b.upper() # No error
My hypothesis is that callable type context for lambda somehow affects how type narrowing behaves.
This was reported by @tueda on Gitter.
PeterJCLaw, kaste, je-l, andersk, Evpok and 5 more
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-strict-optionaltopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder