Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: equality between and abstracttensor and type
Signed-off-by: Johannes Messner <[email protected]>
  • Loading branch information
JohannesMessner committed Jul 31, 2023
commit b5f590edb10dfb5998b674b859bfbd6bc6655036
10 changes: 6 additions & 4 deletions docarray/typing/tensor/abstract_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class _ParametrizedMeta(type):

def _equals_special_case(cls, other):
is_type = isinstance(other, type)
is_tensor = is_type and AbstractTensor in other.mro()
same_parents = is_tensor and cls.mro()[1:] == other.mro()[1:]
is_tensor = is_type and AbstractTensor in other.__mro__
same_parents = is_tensor and cls.mro()[1:] == other.__mro__[1:]

subclass_target_shape = getattr(other, '__docarray_target_shape__', False)
self_target_shape = getattr(cls, '__docarray_target_shape__', False)
Expand Down Expand Up @@ -92,9 +92,11 @@ def __instancecheck__(cls, instance):
return False
return any(
safe_issubclass(candidate, _cls.__unparametrizedcls__)
for candidate in type(instance).mro()
for candidate in type(instance).__mro__
)
return any(issubclass(candidate, cls) for candidate in type(instance).mro())
return any(
issubclass(candidate, cls) for candidate in type(instance).__mro__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

us safe version of is_subclass please

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure if we want that here. This implements the "normal" isinstance() call, so i don't think it should work with non-class inputs. For example, the following also raises an exception:

isinstance(3, List[int])
TypeError: Subscripted generics cannot be used with class and instance checks

So I would not catch such things here

)
return super().__instancecheck__(instance)

def __eq__(cls, other):
Expand Down