From 1f83def62d96c020d7385593201762db7d55e6fb Mon Sep 17 00:00:00 2001 From: James Guthrie Date: Tue, 4 Aug 2015 09:56:39 +0200 Subject: [PATCH] Catch incomplete TypeVisitor implementations Use the @abstractmethod decorator on abstract methods which are implemented in all subtypes. Part of #730 --- mypy/types.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mypy/types.py b/mypy/types.py index 0ea70407481b3..434cd7608cdca 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -486,6 +486,7 @@ class TypeVisitor(Generic[T]): The parameter T is the return type of the visit methods. """ + @abstractmethod def visit_unbound_type(self, t: UnboundType) -> T: pass @@ -495,41 +496,49 @@ def visit_type_list(self, t: TypeList) -> T: def visit_error_type(self, t: ErrorType) -> T: pass + @abstractmethod def visit_any(self, t: AnyType) -> T: pass + @abstractmethod def visit_void(self, t: Void) -> T: pass + @abstractmethod def visit_none_type(self, t: NoneTyp) -> T: pass def visit_erased_type(self, t: ErasedType) -> T: pass + @abstractmethod def visit_type_var(self, t: TypeVarType) -> T: pass + @abstractmethod def visit_instance(self, t: Instance) -> T: pass + @abstractmethod def visit_callable_type(self, t: CallableType) -> T: pass def visit_overloaded(self, t: Overloaded) -> T: pass + @abstractmethod def visit_tuple_type(self, t: TupleType) -> T: pass def visit_star_type(self, t: StarType) -> T: pass + @abstractmethod def visit_union_type(self, t: UnionType) -> T: pass def visit_ellipsis_type(self, t: EllipsisType) -> T: - assert False # XXX catch visitors that don't have this implemented yet + pass class TypeTranslator(TypeVisitor[Type]):