NotImplementedError
Error message
NotImplementedError
Quick summary
You called a method or function that is defined but not yet implemented — a placeholder that needs to be filled in.
Why this happens
Calling an abstract method that hasn't been overridden
Using a stub or placeholder function
Calling a method that a subclass was supposed to implement
Minimal example
class Animal:
def speak(self):
raise NotImplementedError
class Dog(Animal):
pass # Forgot to implement speak
Dog().speak() # NotImplementedErrorclass Animal:
def speak(self):
raise NotImplementedError
class Dog(Animal):
def speak(self):
return "Woof!"
print(Dog().speak()) # Woof!The subclass must implement the abstract method. Dog.speak() now returns 'Woof!' instead of raising NotImplementedError.
How to diagnose
Find the method that raised the error
Check if it contains 'raise NotImplementedError'
Determine what implementation is expected
How to fix
Implement the method in the subclass
Provide the missing functionality
Use ABC (abstract base class) for proper abstract method enforcement
How to prevent
Use abc.ABC and @abstractmethod for abstract methods
Document which methods must be overridden
Implement all required methods before using a class
Related Resources
Related Lessons
- Classes and Objects
Abstract methods.