Skip to content

Unreachability should work for constrained type vars #19256

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:

fromtypingimportTypeVarU=TypeVar('U', int, str)
deff(u: U) ->U:
ifuisNone:
print("whoa!!")
returnu

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