Skip to content

Commit 7fbd8b8

Browse files
authored
include abc.ABCMeta in type coercing condition (#203)
Signed-off-by: weiyang <weiyang.ones@gmail.com>
1 parent e723cb7 commit 7fbd8b8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ring/func/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def coerce_function(t):
214214
if issubclass(t, (list, tuple)):
215215
return _coerce_list_and_tuple
216216

217-
if t is type:
217+
if t is type or t is abc.ABCMeta:
218218
return _coerce_type
219219

220220
if issubclass(t, dict):

tests/test_coerce.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import abc
12
import sys
23

34
import pytest
@@ -37,6 +38,10 @@ def __str__(self):
3738
return str(self.user_id)
3839

3940

41+
class ABCUser(abc.ABC):
42+
pass
43+
44+
4045
ring_key_instance = User(42)
4146
ring_hash_instance = HashUser(42)
4247
test_parameters = [
@@ -49,6 +54,8 @@ def __str__(self):
4954
({1, 2, 3, 4}, "{1,2,3,4}"),
5055
({"1", "2", "3", "4"}, "{'1','2','3','4'}"),
5156
(("1", "2", "3", "4"), "('1','2','3','4')"),
57+
(User, "User"),
58+
(ABCUser, "ABCUser"),
5259
]
5360
if numpy is not None:
5461
test_parameters.extend(

0 commit comments

Comments
 (0)