Skip to content

Unreachability should work for constrained type vars #19256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
A5rocks opened this issue Jun 8, 2025 · 0 comments
Open

Unreachability should work for constrained type vars #19256

A5rocks opened this issue Jun 8, 2025 · 0 comments

Comments

@A5rocks
Copy link
Collaborator

A5rocks commented Jun 8, 2025

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant