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
Narrowed down types sometimes not propagated to lambda #4297
This also seems to happen with native collection types whose size is "runtime" (i.e. recursive types in lambda-calculus terms), but not tuples (whose size is "fixed").
Error / non-error cases added for reproduction, based on the original post:
fromtypingimportOptional, Callabledeff1(key: Callable[[], str]) ->None: ...
deff2(key: object) ->None: ...
defg(b: Optional[str]) ->None:
ifbisnotNone:
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"d= { "foo": lambda: b.upper() } # Item "None" of "Optional[str]" has no attribute "upper"l= [ lambda: b.upper() ] # Item "None" of "Optional[str]" has no attribute "upper"t= ( lambda: b.upper(), ) # No errorf2(lambda: b.upper()) # No errorlambda: b.upper() # No error
Activity
ikonst commentedon Dec 31, 2018
Workaround:
calimeroteknik commentedon Sep 19, 2019
This also seems to happen with native collection types whose size is "runtime" (i.e. recursive types in lambda-calculus terms), but not tuples (whose size is "fixed").
Error / non-error cases added for reproduction, based on the original post:
Fix type narrowing in lambda expressions (#16407)
Fix type narrowing in lambda expressions (#16407)