Python Glossary Русский

all Python 3Built-in typesterm

NotImplemented

special values

A special value a comparison or arithmetic method returns to say "I can't handle this type", letting Python try the reflected operation.

Syntax

def __eq__(self, other):
    if not isinstance(other, Point):
        return NotImplemented

Return NotImplemented itself rather than raising NotImplementedError: the value lets the interpreter try the other operand's method and only then raise TypeError. Since Python 3.14 bool(NotImplemented) raises TypeError — it used to be truthy, so an if result: check silently let mistakes through. It is the sole instance of NotImplementedType and is compared with is.

Examples

class Money:
    def __init__(self, amount):
        self.amount = amount
    def __eq__(self, other):
        if not isinstance(other, Money):
            return NotImplemented
        return self.amount == other.amount
print(Money(5) == Money(5))   # → True
print(Money(5) == 5)   # → False: Python попробовал int.__eq__ и сравнил по тождеству
print(type(NotImplemented).__name__)   # → NotImplementedType
# Python 3.14+
bool(NotImplemented)   # → TypeError: с Python 3.14 в логическом контексте нельзя

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy