basedmypy
basedmypy copied to clipboard
incompatible intersections should become `Never`
a: int & str
reveal_type(a) # int & str, should be Never
Or maybe an error?
Maybe an error if the resulting type is Never, but sections of a type could just evaporate away.
As observed in #469 by @zevbo
from enum import Enum
from typing import Generic, Literal, TypeVar
class E(Enum):
A = 0
B = 1
T = TypeVar("T", Literal[E.A], Literal[E.B])
class A(Generic[T]):
pass
class B(A[Literal[E.A]]):
pass
class C(A[Literal[E.B]]):
pass
TheUnion = B | C
def a(b: A[E.A] & TheUnion) -> B:
return b # Incompatible return value type (got "A[E.A] & B | C", expected "B") [return-value]