Can't narrow Sequence[<X>]
to Tuple[<X>, ...]
using isinstance(..., tuple)
#16933
Labels
Sequence[<X>]
to Tuple[<X>, ...]
using isinstance(..., tuple)
#16933
Bug Report
Using
isinstance(<Sequence[X]>, tuple)
narrows the type of<Sequence[X]>
toTuple[Any, ...]
, notTuple[X, ...]
as one would expect.To Reproduce
[mypy-play.net]
[pyright-play.net1] (pyright handles this as expected)
Expected Behavior
if instance(value, ...)
should only ever narrow the type ofvalue
Actual Behavior
Mypy narrows the container type, but forgets the element type
Your Environment
mypy.ini
(and other config files): (none)Existing issues
While it seems extremely unlikely that this issue hasn't been reported, I haven't been able to locate anything obviously related among the ~217 issues that mention both
isinstance
andtuple
. Issue #2456 may be vaguely related.Footnotes
the pyright example code is slightly modified (1) to avoid an error around
value
being uninitialized, and (2) to reflect that pyright behaves as expected ↩The text was updated successfully, but these errors were encountered: