Repository navigation
Wrong NotImplementedError documentation regarding abstract base classes #158911
Description
Activity
- changed the title
[-]Fix misleading NotImplementedError documentation regarding abstract base classes[/-][+]Misleading NotImplementedError documentation regarding abstract base classes[/+]on Oct 6, 2026 - changed the title
[-]Misleading NotImplementedError documentation regarding abstract base classes[/-][+]Wrong NotImplementedError documentation regarding abstract base classes[/+]on Oct 6, 2026 I don't think this is a correct change nor a valid issue: #158912 (review)
- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Oct 6, 2026 I don't think this is a correct change nor a valid issue: #158912 (review)
I do not agree, the examples from you and Copilot are wrong!
The definition of an abstract method:
An abstract method is a method that is declared without an implementation (it has no code body). It defines a method's signature—> such as its name, parameters, and return type—but leaves the actual logic to be defined by its subclasses.
An abstract method has no code body and therefore a
super()call from the overriding method breaks the basic rules.This rule doesn't hold in Python necessarily. ABCs add overhead at the cost of safety but if you want to define an abstract method in Python, and semantically speaking, you just need to raise NotImplementedError. That's the only role of that exception. Once you use ABCs, the contract is a bit different and people either use "..." or "pass" statements, which btw makes the implementation contain something (there is an implicit
return None)).But the docs for the exception itself are correct.
This rule doesn't hold in Python necessarily. ABCs add overhead at the cost of safety but if you want to define an abstract method in Python, and semantically speaking, you just need to raise NotImplementedError. That's the only role of that exception. Once you use ABCs, the contract is a bit different and people either use "..." or "pass" statements, which btw makes the implementation contain something (there is an implicit
return None)).But the docs for the exception itself are correct.
No, the documentation for the
NotImplementedErrorexception is incorrect. An abstract class-method must always be declared using@abstractmethod(abc module); otherwise, it is not an abstract class-method.This exception is derived from RuntimeError. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.
Please, recheck what exactly an abstract class or method is in C++, Java, or similar languages, given your background in them.
Furthermore, it is false that raising a
NotImplementedErrorinside a method body magically makes it abstract. The concept of abstractness exists precisely to guarantee that if you have multiple child classes, the abstract method must be implemented in all of them.And as a side note: the Python interpreter and the
abcmodule implementation behave 100% correctly according to these abstractness rules; only the documentation states exactly the opposite.Please, recheck what exactly an abstract class or method is in C++, Java, or similar languages, given your background in them.
Those languages have different semantics.
An abstract class-method must always be declared using
@abstractmethod(abc module); otherwise, it is not an abstract class-methodABCs are only for duck typing but semantics can be decided by developers. Having ABCs is a non-trivial overhead. Raising NotImplementedError is a way to declare the intent of an abstract method (in the Python sense) without having to enforce it (that is, without forbidding instantiation). It's not making it abstract at runtime. It's making it abstract semantically. Then users can know that it was meant to be abstract if they hit an issue at runtime. Python doesn't have the same way of contracts as other languages and we apply the consenting adults principle here.
The #100400 issue should be used instead of this one and the tone of the conversation is not civil enough. Should you continue being aggressive, we will restrict your access to our repositories.
I will also no longer interact with you because it doesn't seem you want to hear my arguments.
- locked as too heated and limited conversation to collaborators
on Oct 7, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
Documentation
Python Versions
Python 3.10 / 3.11 / 3.12 / 3.13 / 3.14 / 3.15 / 3.16 beta
Description
The current documentation for
NotImplementedErroron docs.python.org contains a conceptual and technical contradiction regarding its use in abstract class methods.Current cpython Documentation
From
/Doc/builtins/exceptions.rst:"In user-defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added."
The Problem
This documentation text advises developers to raise `NotImplementedError inside abstract class methods.,This is incorrect, as the Python interpreter will never execute the exception-raising code.
Basic Example (Schematic Code)
The Python Interpreter will never output the "I am not able to ..." message which the following code will prove.
PoC Code 1
Calling
i.meow()raises: TypeError: Can't instantiate abstract class Base without an implementation for abstract method 'meow', theNotImplementedErrorexception code never will be executed.PoC Code 2 (Multi-Inheritance)
Calling
i.meow()raises: TypeError: Can't instantiate abstract class Tiger without an implementation for abstract method 'meow', theNotImplementedErrorexception code never will be executed.Correct Context
The Python interpreter behaves 100% correctly. The error lies solely within the Python documentation, which incorrectly recommends the pattern of raising
NotImplementedErrorinside abstract methods.Real-World Impact (Pylint)
The current Python documentation text has a cascading effect on the Python ecosystem. Most notably, Pylint relies heavily on this exact wording for its code checks. Because the documentation explicitly commands that abstract methods should raise this exception, Pylint's abstract method checking has been incorrectly implemented.
Proposed Changes
Suggested Replacement Text:
"In user-defined base classes, any non-abstract method should raise this exception when derived classes are required to override the method, indicating that the real implementation still needs to be added."
References
abstract-method? pylint-dev/pylint#10054 (comment) (current Pylint discussion)Linked PRs