Skip to content

Commit da97735

Browse files
refactor: return NotImplemented instead of raising NotImplementedError
Special methods corresponding to numeric operators, rich comparison operators, and the `__length_hint__` method should return `NotImplemented` when the operation is not supported. These methods should not raise `NotImplementedError` as callers don't expect it and won't catch this exception.
1 parent d5ab32a commit da97735

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

return_not_implemented.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def __init__(self, val):
55
self.val = val
66

77
def __add__(self, other):
8-
raise NotImplementedError
8+
return NotImplemented
99

1010

1111
class ComplexNumber:

0 commit comments

Comments
 (0)