You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tuple length check results in silent error and unreachable code when targeting 3.8 #16763
We encountered this issue while trying to update Streamlit to use mypy 1.8 (streamlit/streamlit#7729)
Code following access of the length of a tuple is considered unreachable by mypy in a confusing way in very specific circumstances:
Mypy must be targeting python 3.8 (probably also happens for earlier versions).
The type of the tuple must be annotated with builtins.tuple (not typing.Tuple) and have subscripted type parameters, in a module that does not use from __future__ import annotations.
The calling code must explicitly call len() with the tuple.
This happening in our code would not be a big deal, since other mypy errors are produced and it is easy to fix. However, it also happens when the tuple's type is defined in a library's module, in which case the errors about tuple not being subscriptable will be suppressed (as expected of type errors in libraries), but the inference that following code is unreachable will remain, which makes for a confusing error.
To Reproduce
While targeting 3.8, in an environment with python 3.9+, with a recent numpy installed (1.26.3 suffices)
Activity
Add # type: ignore[unreachable] comments, for false positive warnings…
Avasam commentedon May 18, 2026
FYI mypy 1.17 has dropped support for Python 3.8:
and mypy 2.0 has dropped support for Python 3.9:
--python-version 3.9#21243