Skip to content

Unreachability should work for constrained type vars #19256

Open
@A5rocks

Description

@A5rocks

Feature

Unreachability should be checked for constrained type vars.

Pitch

It would be nice if this raised an error when run with --warn-unreachable:

from typing import TypeVar

U = TypeVar('U', int, str)

def f(u: U) -> U:
    if u is None:
        print("whoa!!")
    
    return u

To implement this feature, I think we need to store the spans of unreachability for each run, then find the intersection. I thought for a while that we could just treat constrained type variables as if they were bound to the union of constraints, but things like #9424 will happen for things that aren't final (unlike None).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions