Closed
Description
(This came up while playing with descriptors, where the first parameter of __get__
can be either None
or an arbitrary object and you want different return types in the two cases.)
Example reproduction using mypy --strict-optional
on 0.520:
from typing import *
@overload
def a_or_1(obj: None) -> str:
...
@overload
def a_or_1(obj: object) -> int:
# If you change the type of `obj` to e.g. AnyStr, the bug goes away
...
def a_or_1(obj):
if obj is None:
return 'a'
return 1
reveal_type(a_or_1('a string')) # correctly revealed as 'builtins.int'
reveal_type(a_or_1(None)) # revealed as type Any (should be 'builtins.str')