8000 add singledispatchmethod test for objects with equal hash and == · python/cpython@6c6e8b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c6e8b8

Browse files
committed
add singledispatchmethod test for objects with equal hash and ==
1 parent bc262de commit 6c6e8b8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Lib/test/test_functools.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,6 +3228,25 @@ def f(arg):
32283228
def _(arg: undefined):
32293229
return "forward reference"
32303230

3231+
def test_singledispatchmethod_hash_comparision_equal(self):
3232+
from dataclasses import dataclass
3233+
3234+
@dataclass(frozen=True)
3235+
class A:
3236+
value: int
3237+
3238+
@functools.singledispatchmethod
3239+
def dispatch(self, x):
3240+
return id(self)
3241+
3242+
t1 = A(1)
3243+
t2 = A(1)
3244+
3245+
assert t1 == t2
3246+
assert id(t1) == t1.dispatch(2)
3247+
assert id(t2) == t2.dispatch(2) # gh-127750
3248+
3249+
32313250
class CachedCostItem:
32323251
_cost = 1
32333252

0 commit comments

Comments
 (0)
0