File tree Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change 117
117
118
118
from abc import get_cache_token
119
119
from functools import _find_impl # type: ignore # noqa: WPS450
120
+ from types import MethodType
120
121
from typing import ( # noqa: WPS235
121
122
TYPE_CHECKING ,
122
123
Callable ,
@@ -499,6 +500,8 @@ def instance(
499
500
self ,
500
501
type_argument : Optional [_NewInstanceType ],
501
502
* ,
503
+ # TODO: at one point I would like to remove `is_protocol`
504
+ # and make this function decide whether this type is protocol or not.
502
505
is_protocol : bool = False ,
503
506
) -> '_TypeClassInstanceDef[_NewInstanceType, _TypeClassType]' :
504
507
"""
@@ -520,7 +523,7 @@ def decorator(implementation):
520
523
container = self ._protocols if is_protocol else self ._instances
521
524
container [type_argument ] = implementation # type: ignore
522
525
523
- if getattr (type_argument , ' __instancecheck__' , None ):
526
+ if isinstance (type_argument . __instancecheck__ , MethodType ):
524
527
# This means that this type has `__instancecheck__` defined,
525
528
# which allows dynamic checks of what `isinstance` of this type.
526
529
# That's why we also treat this type as a protocol.
Original file line number Diff line number Diff line change @@ -32,4 +32,5 @@ def _my_len_list(instance: list) -> int:
32
32
])
33
33
def test_call_order (data_type , expected ):
34
34
"""Ensures that call order is correct."""
35
+ print (my_len ._protocols )
35
36
assert my_len (data_type ) == expected
You can’t perform that action at this time.
0 commit comments