basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

incompatible intersections should become `Never`

Open DetachHead opened this issue 2 years ago • 2 comments

a: int & str
reveal_type(a)  # int & str, should be Never

DetachHead avatar Mar 29 '23 07:03 DetachHead

Or maybe an error?

Maybe an error if the resulting type is Never, but sections of a type could just evaporate away.

KotlinIsland avatar Mar 29 '23 08:03 KotlinIsland

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]

KotlinIsland avatar Jun 02 '23 00:06 KotlinIsland