Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

NotImplemented

NotImplemented is a singleton that an operator method can return to decline an operand pairing.

Version: Python 3.14; repository image, production runtime not attested

Syntax

return NotImplemented

NotImplemented is a singleton that an operator method can return to decline an operand pairing.

NotImplemented

The interpreter may try a reflected operation or the applicable final fallback. It is a return value distinct from the NotImplementedError exception. Since Python 3.14 bool(NotImplemented) raises TypeError.

The left addition declines and the right operand handles it, yielding handled.

class No:
    def __add__(self,other): return NotImplemented
a=No()
assert No.__add__(a,1) is NotImplemented
try: a+1
except TypeError: pass
else: raise AssertionError
assert not (object()==object())

Examples

class Left:
    def __add__(self, other): return NotImplemented
class Right:
    def __radd__(self, other): return "handled"
print(Left() + Right())
try: bool(NotImplemented)
except TypeError as exc: print(type(exc).__name__)

Result

handled
TypeError

The left addition declines and the right operand handles it, yielding handled.

Sources