Check instantiation of abstract classes [abstract]

Mypy generates an error if you try to instantiate an abstract baseclass (ABC). An abtract base class is a class with at least oneabstract method or attribute. (See also abc module documentation)

Sometimes a class is made accidentally abstract, often due to anunimplemented abstract method. In a case like this you need to providean implementation for the method to make the class concrete(non-abstract).

Example:

  1. from abc import ABCMeta, abstractmethod
  2.  
  3. class Persistent(metaclass=ABCMeta):
  4. @abstractmethod
  5. def save(self) -> None: ...
  6.  
  7. class Thing(Persistent):
  8. def __init__(self) -> None:
  9. ...
  10.  
  11. ... # No "save" method
  12.  
  13. # Error: Cannot instantiate abstract class 'Thing' with abstract attribute 'save' [abstract]
  14. t = Thing()