Closed
Description
The type checker may use context to infer an invalid type variable value for a type variable such as AnyStr:
from typing import AnyStr
def f(x: AnyStr) -> AnyStr:
if isinstance(x, str):
return 'foo'
else:
return b'zar'
print(repr(f(''))) # Type argument 1 of "f" has incompatible value "object"
We should probably not use type context in cases like this when the type variable is not used within a generic type.