raise NotImplementedshould be
19 self.limits = (1, 10) 20 21 def get_number(self, min_max): 22 raise NotImplemented 23 24 def smethod(): 25 """static method-to-be"""
NotImplemented would be fine, raising it doesn't work and will cause a
NotImplemented is not an exception type.
NotImplemented signals to the runtime that it should ask someone else to satisfy the operation. In the expression
a == b, if
NotImplemented, then Python tries
b knows enough to return
False, then the expression can succeed. If it doesn't, the runtime will fall back to the built-in behavior (based on identity for
class MyClass: def __lt__(self, other): raise NotImplemented # This will raise a TypeError, as NotImplemented cannot be raised
If you want to disallow comparison with this class:
class MyClass: def __lt__(self, other): raise NotImplementedError # Will raise the exception
class MyClass: def __lt__(self, other): return NotImplemented # Will allow Python to figure out the value