|
1 | 1 | from typing import Sequence |
2 | 2 |
|
3 | 3 | from mypy.types import ( |
4 | | - Type, UnboundType, AnyType, NoneType, TupleType, TypedDictType, |
| 4 | + Type, TypeGuardType, UnboundType, AnyType, NoneType, TupleType, TypedDictType, |
5 | 5 | UnionType, CallableType, TypeVarType, Instance, TypeVisitor, ErasedType, |
6 | 6 | Overloaded, PartialType, DeletedType, UninhabitedType, TypeType, LiteralType, |
7 | 7 | ProperType, get_proper_type, TypeAliasType) |
|
10 | 10 |
|
11 | 11 | def is_same_type(left: Type, right: Type) -> bool: |
12 | 12 | """Is 'left' the same type as 'right'?""" |
| 13 | + |
13 | 14 | left = get_proper_type(left) |
14 | 15 | right = get_proper_type(right) |
15 | 16 |
|
@@ -150,6 +151,12 @@ def visit_union_type(self, left: UnionType) -> bool: |
150 | 151 | else: |
151 | 152 | return False |
152 | 153 |
|
| 154 | + def visit_type_guard_type(self, left: TypeGuardType) -> bool: |
| 155 | + if isinstance(self.right, TypeGuardType): |
| 156 | + return is_same_type(left.type_guard, self.right.type_guard) |
| 157 | + else: |
| 158 | + return False |
| 159 | + |
153 | 160 | def visit_overloaded(self, left: Overloaded) -> bool: |
154 | 161 | if isinstance(self.right, Overloaded): |
155 | 162 | return is_same_types(left.items(), self.right.items()) |
|
0 commit comments