[math] Fix Shaped instancecheck
@@ -23,12 +23,10 @@ from ._shape import Shape, shape, batch, spatial, instance, channel, non_batch
class _ShapedType(type):
def __instancecheck__(self, instance):
- if hasattr(instance, '__shape__'):
- return True
- if isinstance(instance, (int, float, complex, bool)):
- return True
- if hasattr(instance, 'shape') and isinstance(instance.shape, Shape):
+ try:
+ shape(instance)
return True
+ except ValueError:
return False
def __subclasscheck__(self, subclass):
