Skip to content

Commit 0e17a92

Browse files
JamesGuthrieJukkaL
authored andcommitted
Raise error on unimplemented abstract method call
This helps to point out the offending unimplemented abstract methods in subtypes. Part of #730.
1 parent 8710aaf commit 0e17a92

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mypy/types.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,21 @@ class TypeVisitor(Generic[T]):
499499
The parameter T is the return type of the visit methods.
500500
"""
501501

502+
def _notimplemented_helper(self) -> NotImplementedError:
503+
return NotImplementedError("Method visit_type_list not implemented in "
504+
+ "'{}'\n".format(type(self).__name__)
505+
+ "This is a known bug, track development in "
506+
+ "'https://github.com/JukkaL/mypy/issues/730'")
507+
502508
@abstractmethod
503509
def visit_unbound_type(self, t: UnboundType) -> T:
504510
pass
505511

506512
def visit_type_list(self, t: TypeList) -> T:
507-
pass
513+
raise self._notimplemented_helper()
508514

509515
def visit_error_type(self, t: ErrorType) -> T:
510-
pass
516+
raise self._notimplemented_helper()
511517

512518
@abstractmethod
513519
def visit_any(self, t: AnyType) -> T:
@@ -522,7 +528,7 @@ def visit_none_type(self, t: NoneTyp) -> T:
522528
pass
523529

524530
def visit_erased_type(self, t: ErasedType) -> T:
525-
pass
531+
raise self._notimplemented_helper()
526532

527533
@abstractmethod
528534
def visit_type_var(self, t: TypeVarType) -> T:
@@ -537,21 +543,21 @@ def visit_callable_type(self, t: CallableType) -> T:
537543
pass
538544

539545
def visit_overloaded(self, t: Overloaded) -> T:
540-
pass
546+
raise self._notimplemented_helper()
541547

542548
@abstractmethod
543549
def visit_tuple_type(self, t: TupleType) -> T:
544550
pass
545551

546552
def visit_star_type(self, t: StarType) -> T:
547-
pass
553+
raise self._notimplemented_helper()
548554

549555
@abstractmethod
550556
def visit_union_type(self, t: UnionType) -> T:
551557
pass
552558

553559
def visit_ellipsis_type(self, t: EllipsisType) -> T:
554-
pass
560+
raise self._notimplemented_helper()
555561

556562

557563
class TypeTranslator(TypeVisitor[Type]):

0 commit comments

Comments
 (0)