Skip to content

How to Fix NotImplementedError in Python

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix NotImplementedError in Python. We cover key concepts, practical examples, and best practices.

Python raises NotImplementedError when a method that is meant to be overridden by a subclass has not been implemented.

The Wrong Way

class BaseProcessor:
    def process(self, data):
        raise NotImplementedError("Subclasses must implement process()")

class CSVProcessor(BaseProcessor):
    pass  # forgot to implement process()

p = CSVProcessor()
p.process("data")

This produces:

Traceback (most recent call last):
  File "script.py", line 9, in <module>
    p.process("data")
  File "script.py", line 3, in process
    raise NotImplementedError("Subclasses must implement process()")
NotImplementedError: Subclasses must implement process()

The Right Way

Implement the required method in the subclass:

class BaseProcessor:
    def process(self, data):
        raise NotImplementedError("Subclasses must implement process()")

class CSVProcessor(BaseProcessor):
    def process(self, data):
        return f"Processing CSV: {data}"

p = CSVProcessor()
result = p.process("data")
print(result)

Output:

Processing CSV: data

Step-by-Step Fix

1. Use ABC and abstractmethod for compile-time checking

from abc import ABC, abstractmethod

class BaseProcessor(ABC):
    @abstractmethod
    def process(self, data):
        pass

class CSVProcessor(BaseProcessor):
    def process(self, data):
        return f"Processing CSV: {data}"

# This will raise TypeError at instantiation if process is not implemented

2. Check for typos in the method name

class CSVProcessor(BaseProcessor):
    def proces(self, data):  # typo -- missing 's'
        pass

3. Implement all required methods

class Shape:
    def area(self):
        raise NotImplementedError

    def perimeter(self):
        raise NotImplementedError

class Rectangle(Shape):
    def __init__(self, w, h):
        self.w = w
        self.h = h

    def area(self):
        return self.w * self.h

    def perimeter(self):
        return 2 * (self.w + self.h)

r = Rectangle(3, 4)
print(r.area())
print(r.perimeter())

Output:

12
14

Prevention Tips

  • Use abc.ABC and @abstractmethod for abstract base classes.
  • Instantiate the subclass early in development to catch missing methods.
  • Use a linter to detect missing method implementations.
  • Write unit tests that call every method of the interface.
  • Use type hints and mypy to verify interface compliance.

Common Mistakes with notimplementederror

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between NotImplementedError and NotImplemented?

NotImplementedError is an exception class for abstract methods that must be overridden. NotImplemented is a singleton used by comparison operators to indicate that comparison is not implemented for the given types.

Should I use NotImplementedError or ABC?

Use ABC with @abstractmethod when you want Python to catch the error at instantiation time. Use NotImplementedError when you want the error to be raised only when the method is actually called.

Can I catch NotImplementedError?

Yes, it is a regular exception. But catching it usually indicates a design problem -- you should implement the method rather than handle the error at runtime.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro