Ad Space — Top Banner

NotImplementedError

Python Programming Language

Severity: Minor

What Does This Error Mean?

NotImplementedError means you called a method that is defined in a base class but has not been implemented in the sub-class you are using. It is like a placeholder that says 'you need to write this part yourself'. Library authors use it to mark methods that every sub-class must provide its own version of.

Affected Models

  • Python 2.x
  • Python 3.x
  • All Python versions using class inheritance

Common Causes

  • Calling a method on a sub-class that was marked as abstract in its parent class but was never overridden
  • Using a third-party library class that requires you to sub-class it and implement certain methods
  • Instantiating a base class directly that was designed to be used only as a parent — not on its own
  • A method was recently added to an interface/base class but the sub-class has not been updated yet
  • Calling super().method() that intentionally raises NotImplementedError to force sub-class implementation

How to Fix It

  1. Read the traceback carefully. It shows which class and method raised NotImplementedError. Go to your sub-class and check whether you have overridden that method.

    If you see 'raise NotImplementedError' inside a base class method, that is intentional — the author is telling you: sub-classes must implement this.

  2. Add the missing method to your sub-class. Look at the base class method signature (the parameter names) to understand what inputs it takes and what it should return.

    Example: if the base class has 'def process(self, data): raise NotImplementedError', add 'def process(self, data): return data.strip()' in your sub-class.

  3. Read the library's documentation or examples. Most libraries that use NotImplementedError explain exactly what each method should do in their docs.

    Look for phrases like 'subclasses must implement' or 'abstract method' in the docs — these tell you which methods you need to provide.

  4. If you are using Python's abc module (Abstract Base Classes), your sub-class must implement every method decorated with @abstractmethod. Forgetting even one will cause an error when you try to instantiate the class.

    Python will tell you 'Can't instantiate abstract class X with abstract method Y' — implement method Y to fix it.

  5. If you are writing a base class yourself, use the abc module and @abstractmethod decorator instead of manually raising NotImplementedError. Python then enforces the requirement at class creation time, not at call time.

    from abc import ABC, abstractmethod. Then: class Base(ABC): @abstractmethod def process(self, data): pass

When to Call a Professional

NotImplementedError is always a code design issue — you need to implement the missing method. Read the documentation for the class or library to find out exactly what the method should do. This error is never a system or environment problem.

Frequently Asked Questions

What is the difference between NotImplementedError and NotImplemented?

They sound similar but are completely different things. NotImplementedError is an exception you raise to say 'this method needs to be implemented by a sub-class'. NotImplemented (without Error) is a special constant you return from comparison methods like __eq__ to say 'I don't know how to compare with this type, let the other object try'. Never raise NotImplemented as an exception — that is always a bug.

Can I catch NotImplementedError?

You can, but you almost never should. NotImplementedError signals a programming error — a method that was supposed to be implemented was not. Catching it hides the bug rather than fixing it. The correct response is to implement the missing method. The only exception is if you are writing framework code that detects missing implementations and provides a fallback.

Is NotImplementedError the same as a method that does not exist?

No. If a method does not exist at all, you get AttributeError. NotImplementedError means the method exists — it just deliberately raises this error as a signal that sub-classes must override it. Think of it as a 'you must fill this in' marker left by the library author.