Update docs

This commit is contained in:
Joe Farebrother
2025-07-24 16:01:57 +01:00
parent 362bfba049
commit 871688f026
7 changed files with 52 additions and 79 deletions

View File

@@ -0,0 +1,22 @@
class A:
def __init__(self, a):
self.a = a
def __add__(self, other):
# BAD: Should return NotImplemented instead of raising
if not isinstance(other,A):
raise TypeError(f"Cannot add A to {other.__type__}")
return A(self.a + other.a)
class B:
def __init__(self, a):
self.a = a
def __add__(self, other):
# GOOD: Returning NotImplemented allows for other classes to support adding do B.
if not isinstance(other,B):
return NotImplemented
return B(self.a + other.a)