Let's say I have the following abstract class Foo :
import abc class Foo(abc.ABC): @abc.abstractmethod def bar(self): raise NotImplementedError
What should I put in the body of the bar method?
I see a lot of code that has raise NotImplementedError as shown above. However, this seems redundant, since any subclass that does not implement bar will fine-tune TypeError: Can't instantiate abstract class Foo with abstract methods bar when it is created.
Can Pythonic leave bar empty as follows:
import abc class Foo(abc.ABC): @abc.abstractmethod def bar(self): ...
This is what is done in Python docs for Abstract base classes , but I'm not sure if this is just a placeholder or an actual example of how to write code.
If bar left with only three points ( ... ), when should I use NotImplementedError ?
source share