Skip to content

Commit

Permalink
Catch incomplete TypeVisitor implementations
Browse files Browse the repository at this point in the history
Use the @AbstractMethod decorator on abstract methods which are
implemented in all subtypes. Part of python#730
  • Loading branch information
JamesGuthrie committed Aug 24, 2015
1 parent fccaca8 commit 1f83def
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]):
Expand Down

0 comments on commit 1f83def

Please sign in to comment.