Avoid false "Incompatible return value type" errors when dealing with `isinstance`, constrained type variables and multiple inheritance (Fixes #13800)
Avoid false "Incompatible return value type" errors when dealing with isinstance, constrained type variables and multiple inheritance (Fixes #13800).
The idea is to make a union of the current expanded return type and the previously expanded return types if the latter are among the bases of intersections generated by isinstance checks.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
@hauntsaninja: I could not resist checking if I could solve the issue relatively cleanly. Mypy's multi-pass approach for constrained type variables makes my solution more "global" than I hoped (I mean the addition of a new TypeChecker attribute). Still, it is not too invasive, in my opinion. Would you like to review it?