Skip to content

[red-knot] T & ~X should be assignable to T #17364

@carljm

Description

@carljm

This does not type check, but it should:

def union_param[T](x: T | None) -> T:
    if x is None:
        raise ValueError("don't give me that none")
    return x  # bogus error: expected T, found T & ~None

The equivalent where we replace T with a concrete type, does type check:

def union_param(x: int | None) -> int:
    if x is None:
        raise ValueError("don't give me that none")
    return x

Placing this in alpha milestone because I've run into it already several times, I think it will be a common source of false positives in generic functions.

Metadata

Metadata

Assignees

Labels

tyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions