NotImplementedError: What It Means and How to Fix It
Error reference
NotImplementedError
Language
Severity
LowWhen it happens
A NotImplementedError is raised deliberately by a developer to signal that a method or function has not been implemented yet.
Potential fixes
Implement the required method in your subclass. Search for every raise NotImplementedError in the base class you are extending to know which methods you must override. Consider using Python's abc module (ABC and @abstractmethod) to get an earlier, clearer error at class instantiation time rather than at call time.
Related errors
Deep dive
A NotImplementedError is raised deliberately by a developer to signal that a method or function has not been implemented yet. It is commonly used in abstract base classes to enforce that all subclasses provide their own implementation of a required method.
Why it happens
- •A subclass inherits from a base class but forgets to override a method that raises NotImplementedError.
- •Calling a stub method that was added as a placeholder during development.
- •Attempting to use an abstract interface method directly instead of through a concrete subclass.
- •A third-party library method that is documented as requiring a subclass implementation.
Potential fixes
Implement the required method in your subclass. Search for every raise NotImplementedError in the base class you are extending to know which methods you must override. Consider using Python's abc module (ABC and @abstractmethod) to get an earlier, clearer error at class instantiation time rather than at call time.
Examples
Code that triggers the error
class Animal:
def speak(self):
raise NotImplementedError("Subclasses must implement speak()")
class Dog(Animal):
pass # forgot to implement speak()
dog = Dog()
dog.speak()Error output
Traceback (most recent call last):
File "app.py", line 9, in <module>
dog.speak()
NotImplementedError: Subclasses must implement speak()Fixed code
class Animal:
def speak(self) -> str:
raise NotImplementedError("Subclasses must implement speak()")
class Dog(Animal):
def speak(self) -> str:
return "Woof!"
dog = Dog()
print(dog.speak()) # Woof!Practice in English
How would you explain a NotImplementedError to a fellow dev? Choose the right phrase:
"I hit an error...
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free