Skip to content

Commit 065162a

Browse files
authored
fix problem with functools.singledispatch (#104) (#105)
solves #104
1 parent da29a2d commit 065162a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

dirty_equals/_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class DirtyEqualsMeta(ABCMeta):
1515
def __eq__(self, other: Any) -> bool:
16+
if self is other:
17+
return True
18+
1619
# this is required as fancy things happen when creating generics which include equals checks, without it,
1720
# we get some recursive errors
1821
if self is DirtyEquals or other is Generic or other is Protocol:

tests/test_base.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import platform
22
import pprint
3+
from functools import singledispatch
34

45
import packaging.version
56
import pytest
67

7-
from dirty_equals import Contains, IsApprox, IsInt, IsList, IsNegative, IsOneOf, IsPositive, IsStr
8+
from dirty_equals import Contains, DirtyEquals, IsApprox, IsInt, IsList, IsNegative, IsOneOf, IsPositive, IsStr
89
from dirty_equals.version import VERSION
910

1011

@@ -192,3 +193,23 @@ def test_is_one_of(value, dirty):
192193

193194
def test_version():
194195
packaging.version.parse(VERSION)
196+
197+
198+
def test_singledispatch():
199+
@singledispatch
200+
def dispatch(value):
201+
return 'generic'
202+
203+
assert dispatch(IsStr()) == 'generic'
204+
205+
@dispatch.register
206+
def _(value: DirtyEquals):
207+
return 'DirtyEquals'
208+
209+
assert dispatch(IsStr()) == 'DirtyEquals'
210+
211+
@dispatch.register
212+
def _(value: IsStr):
213+
return 'IsStr'
214+
215+
assert dispatch(IsStr()) == 'IsStr'

0 commit comments

Comments
 (0)