Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
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
5 changes: 5 additions & 0 deletions tests/units/typing/tensor/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ class MyTensorDoc(BaseDoc):
assert isinstance(doc.tensor, TensorFlowTensor)
assert isinstance(doc.tensor.tensor, tf.Tensor)
assert tnp.allclose(doc.tensor.tensor, tf.zeros((1000, 2)))


def test_equals_type():
# see https://github.com/docarray/docarray/pull/1739
assert not (TorchTensor == type)