abstractmethod is not defined abstractmethod is not defined python python

abstractmethod is not defined


You only imported ABCMeta

from abc import ABCMeta

Also import abstractmethod

from abc import ABCMeta, abstractmethod

and everything should be fine.


You need to import abstractmethod from abc. abc is the inbuilt Python package for Abstract Base Classes.

An example:

from abc import abstractmethodclass Foo:    def __init():        pass        @abstractmethod    def bar():        pass


You need to change import ABC to ABCMeta

from abc import ABCMeta, abstractmethodclass AbstractClassExample(ABCMeta):    def __init__(self, value):        self.value = value        super().__init__()    @abstractmethod    def do_something(self):        print("do_something")class DoAdd42(AbstractClassExample):    print("DoAdd42")x = DoAdd42(4)