mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Avoid false "Incompatible return value type" errors when dealing with `isinstance`, constrained type variables and multiple inheritance (Fixes #13800)

Open tyralla opened this issue 3 years ago • 2 comments

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.

tyralla avatar Jan 04 '23 09:01 tyralla

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Jan 04 '23 10:01 github-actions[bot]

@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?

tyralla avatar Jan 04 '23 10:01 tyralla