Skip to content

Intersection between @final class and Callable is not reduced to Never #513

@JelleZijlstra

Description

@JelleZijlstra

Summary

An intersection like bool & Callable[..., int] should be Never, because bool can't have any subclasses that are callable. But ty treats it as irreducible.

from typing import Callable, reveal_type, Literal, final
from ty_extensions import Intersection

@final
class C:
    pass

def f(
    x: Intersection[bool, Callable[..., int]],
    y: Intersection[Literal[1], Callable[..., int]],
    z: Intersection[C, Callable[..., int]],
):
    reveal_type(x)  # bool & ((...) -> int), expect Never
    reveal_type(y)  # Never (correct)
    reveal_type(z)  # C & (...) -> int), expect Never

https://play.ty.dev/979ab089-7157-44ad-a94a-868260108090

An intersection between a final class and a non-applicable Protocol is correctly reduced to Never though.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingset-theoretic typesunions, intersections and more

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions