NotImplemented
Prev: None | Up: __builtins__ | Next: True
Rel: True, False, None, Ellipsis, copyright
Ref: docs.python.org — NotImplemented
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import NotImplemented
Overview & Signature
NotImplemented -> NotImplementedType
The type of the NotImplemented singleton.
Usage
class Box:
def __init__(self, val: int) -> None: self.val = val
def __eq__(self, other: object) -> bool:
if not isinstance(other, Box):
return NotImplemented
return self.val == other.val
assert Box(3) == Box(3) and (Box(3) == 3) is False
Gotchas
- Return
NotImplemented, do NOTraise NotImplementedErrorinside binary dunder methods (__eq__,__lt__,__add__): returningNotImplementedtells Python to try the reflected method (other.__radd__) before giving up.
REPL Inspect
help(NotImplemented)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/copyright
- tuts/python3/__builtins__/credits
- tuts/python3/__builtins__/Ellipsis
- tuts/python3/__builtins__/exit
- tuts/python3/__builtins__/False
- tuts/python3/__builtins__/help
- tuts/python3/__builtins__/license
- tuts/python3/__builtins__/None
- tuts/python3/__builtins__/quit
- tuts/python3/__builtins__/True
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/copyright Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/Ellipsis Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/False Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/None Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/True Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/credits links to this page; shared tags: #builtins
- tuts/python3/__builtins__/exit links to this page; shared tags: #builtins
- tuts/python3/__builtins__/help links to this page; shared tags: #builtins