Skip to content

Commit fefd403

Browse files
committed
Comparable
1 parent 311c4a7 commit fefd403

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ class MyComparable:
876876
def __eq__(self, other):
877877
if isinstance(other, type(self)):
878878
return self.a == other.a
879-
return False
879+
return NotImplemented
880880
```
881881

882882
### Hashable
@@ -894,7 +894,7 @@ class MyHashable:
894894
def __eq__(self, other):
895895
if isinstance(other, type(self)):
896896
return self.a == other.a
897-
return False
897+
return NotImplemented
898898
def __hash__(self):
899899
return hash(self.a)
900900
```

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ <h3 id="comparable">Comparable</h3>
782782
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__eq__</span><span class="hljs-params">(self, other)</span>:</span>
783783
<span class="hljs-keyword">if</span> isinstance(other, type(self)):
784784
<span class="hljs-keyword">return</span> self.a == other.a
785-
<span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>
785+
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
786786
</code></pre>
787787
<h3 id="hashable">Hashable</h3>
788788
<ul>
@@ -799,7 +799,7 @@ <h3 id="hashable">Hashable</h3>
799799
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__eq__</span><span class="hljs-params">(self, other)</span>:</span>
800800
<span class="hljs-keyword">if</span> isinstance(other, type(self)):
801801
<span class="hljs-keyword">return</span> self.a == other.a
802-
<span class="hljs-keyword">return</span> <span class="hljs-keyword">False</span>
802+
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
803803
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__hash__</span><span class="hljs-params">(self)</span>:</span>
804804
<span class="hljs-keyword">return</span> hash(self.a)
805805
</code></pre>

0 commit comments

Comments
 (0)