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
Trying to narrow T | Sequence[T] with isinstance clauses leads to type errors. I believe this has to do with the example below actually wanting T | (Sequence[T] & ¬T).
So in the first clause, I guess mypy thinks this could be either L & Foo = Foo or Sequence[L] & Foo, which is not necessarily an instance of L. (so maybe not a bug but nevertheless a serious divergence between type checkers).
This has the same reason as #15151: narrowing a bounded TypeVar currently produces whatever isinstance narrows to, TypeVar is essentially forgotten in such cases. This is fixed by #19183 (I checked out the PR and confirmed that that revision returns green for your snippet)
Uh oh!
There was an error while loading. Please reload this page.
Trying to narrow
T | Sequence[T]
withisinstance
clauses leads to type errors. I believe this has to do with the example below actually wantingT | (Sequence[T] & ¬T)
.So in the first clause, I guess
mypy
thinks this could be eitherL & Foo = Foo
orSequence[L] & Foo
, which is not necessarily an instance ofL
. (so maybe not a bug but nevertheless a serious divergence between type checkers).To Reproduce
Expected Behavior
This code passes without issues in
pyright-playground
andty-playground
Actual Behavior
mypy-playground
emits 6 errorsAt the very least, the error messages are misleading, since the problematic bit are the arguments to
SeqFoo
, not totuple
.The text was updated successfully, but these errors were encountered: