Lingua-e
Python

What is a NotImplementedError?

← Errors

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.

Examples

Python

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()

How to fix it

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.

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!

Related errors

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