This page explains Python
NotImplemented constant, its typical use cases, and its difference from
Typical use cases
NotImplemented constant is used to indicate that an operation or method is not implemented for a given object.
It is typically used with comparison methods such as
__gt__(), when comparison between the two objects does not make sense or is not implemented.
In abstract base classes, a method can be defined but left unimplemented by returning the
NotImplemented constant. This allows individual subclasses to provide their own implementation. If a subclass does not have an implementation, a
TypeError will be raised when the method is called.
NotImplenented constant has its own special data type
>>> type(NotImplemented) <class 'NotImplementedType'>
NotImplemented vs. NotImplementedError
NotImplemented (constant) is different from
>>> a = NotImplemented >>> a NotImplemented >>> type(a) <class 'NotImplementedType'> >>> >>> b = NotImplementedError >>> b <class 'NotImplementedError'> >>> type(b) <class 'type'>
>>> raise NotImplementedError Traceback (most recent call last): File "<stdin>", line 1, in <module> NotImplementedError >>> raise NotImplemented Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: exceptions must derive from BaseException
Official documentation at docs.python.org