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).
I experimented with the IterationErrorWatcher proposed in #19270 and was successful in the first simple attempt. However, as many existing tests would require adjustment and some new ones should be introduced (which might reveal the need to adjust the method eventually), I will wait to work on it until #19270 is accepted.
By the way, aren't classes with type variables with value constraints a problem, too?
Activity
tyralla commented on Jun 12, 2025
I investigated a little, and this limitation seems to have been known for a while:
mypy/test-data/unit/check-unreachable-code.test
Lines 1036 to 1049 in 8241059
mypy/mypy/checker.py
Lines 1467 to 1475 in 8241059
I experimented with the IterationErrorWatcher proposed in #19270 and was successful in the first simple attempt. However, as many existing tests would require adjustment and some new ones should be introduced (which might reveal the need to adjust the method eventually), I will wait to work on it until #19270 is accepted.
By the way, aren't classes with type variables with value constraints a problem, too?
Fix `--strict-equality` for iteratively visited code (#19635)
Check functions with constrained type variable parameters for unreach…