mypy
23e02e20 - Fixes mypy crash on protocol with contravariant var (#11135)

Commit
4 years ago
Fixes mypy crash on protocol with contravariant var (#11135) Closes #11020 * Fixes mypy crash on protocol with contravariant var * Fixes how `infer_constraints_from_protocol_members` works Here's what was wrong: 1. When checking if some type is a subtype of a protocol, we iterate over all its members 2. When we are inside `is_protocol_implementation` we set `.assuming` or `.assuming_proper` attributes and continue to check the other members 3. While checking methods with annotated `self` type with a protocol itself, we recurse into `is_protocol_implementation` once again 4. It always returns `True` in this case, because `assuming` is set in the context above 5. Because `is_protocol_implementation` is set to `True`, we dive into `infer_constraints_from_protocol_members` with a type, which is not really a protocol implementation 6. Sanity check breaks! Solution: return empty constraints instead of raising `AssertionError`
Author
Parents
Loading