CKTIS / Python
NotImplemented
NotImplemented je jedinstveni objekt kojim metoda operatora može odbiti par operanada.
Verzija: Python 3.14; repository image, production runtime not attested
Sintaksa
return NotImplementedNotImplemented je jedinstveni objekt kojim metoda operatora može odbiti par operanada.
NotImplemented
Interpreter može pokušati zrcalnu operaciju ili odgovarajuće završno pravilo. Povratna vrijednost razlikuje se od iznimke NotImplementedError. Od Pythona 3.14 bool(NotImplemented) izaziva TypeError.
Lijevo zbrajanje odbija, desni operand preuzima operaciju i vraća 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())
Primjeri
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__)
Rezultat
handled TypeError
Lijevo zbrajanje odbija, desni operand preuzima operaciju i vraća handled.