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:
- from abc import ABCMeta, abstractmethod
- class Persistent(metaclass=ABCMeta):
- @abstractmethod
- def save(self) -> None: ...
- class Thing(Persistent):
- def __init__(self) -> None:
- ...
- ... # No "save" method
- # Error: Cannot instantiate abstract class 'Thing' with abstract attribute 'save' [abstract]
- t = Thing()