diff --git a/mypy/join.py b/mypy/join.py index 23838ffad5ed..45b8bde47dc0 100644 --- a/mypy/join.py +++ b/mypy/join.py @@ -433,7 +433,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> ProperType: assert False, "This should be never called, got {}".format(t) def visit_type_guard_type(self, t: TypeGuardType) -> ProperType: - assert False, "This should be never called, got {}".format(t) + return t.type_guard.accept(self) def join(self, s: Type, t: Type) -> ProperType: return join_types(s, t) diff --git a/test-data/unit/check-typeguard.test b/test-data/unit/check-typeguard.test index fa340cb04044..56fcecece4bf 100644 --- a/test-data/unit/check-typeguard.test +++ b/test-data/unit/check-typeguard.test @@ -315,3 +315,17 @@ def coverage(obj: Any) -> bool: return True return False [builtins fixtures/classmethod.pyi] + +[case testTypeGuardAssignment] +from typing_extensions import TypeGuard + +class A: pass +class B(A): pass + +def guard(a: A) -> TypeGuard[B]: + pass + +a = A() +if not guard(a): + a = A() +[builtins fixtures/tuple.pyi]