3131from docarray .base_doc .mixins .io import _type_to_protobuf
3232from docarray .typing import NdArray
3333from docarray .typing .tensor .abstract_tensor import AbstractTensor
34- from docarray .utils ._internal ._typing import is_tensor_union
34+ from docarray .utils ._internal ._typing import is_tensor_union , safe_issubclass
3535from docarray .utils ._internal .misc import is_tf_available , is_torch_available
3636
3737if TYPE_CHECKING :
@@ -198,7 +198,7 @@ def __init__(
198198 for field_name , field in self .doc_type .__fields__ .items ():
199199 # here we iterate over the field of the docs schema, and we collect the data
200200 # from each document and put them in the corresponding column
201- field_type = self .doc_type ._get_field_type (field_name )
201+ field_type : Type = self .doc_type ._get_field_type (field_name )
202202
203203 is_field_required = self .doc_type .__fields__ [field_name ].required
204204
@@ -231,19 +231,19 @@ def _check_doc_field_not_none(field_name, doc):
231231 field_type = tensor_type
232232 # all generic tensor types such as AnyTensor, ImageTensor, etc. are subclasses of AbstractTensor.
233233 # Perform check only if the field_type is not an alias and is a subclass of AbstractTensor
234- elif not isinstance (field_type , typingGenericAlias ) and issubclass (
234+ elif not isinstance (field_type , typingGenericAlias ) and safe_issubclass (
235235 field_type , AbstractTensor
236236 ):
237237 # check if the tensor associated with the field_name in the document is a subclass of the tensor_type
238238 # e.g. if the field_type is AnyTensor but the type(docs[0][field_name]) is ImageTensor,
239239 # then we change the field_type to ImageTensor, since AnyTensor is a union of all the tensor types
240240 # and does not override any methods of specific tensor types
241241 tensor = getattr (docs [0 ], field_name )
242- if issubclass (tensor .__class__ , tensor_type ):
242+ if safe_issubclass (tensor .__class__ , tensor_type ):
243243 field_type = tensor_type
244244
245245 if isinstance (field_type , type ):
246- if tf_available and issubclass (field_type , TensorFlowTensor ):
246+ if tf_available and safe_issubclass (field_type , TensorFlowTensor ):
247247 # tf.Tensor does not allow item assignment, therefore the
248248 # optimized way
249249 # of initializing an empty array and assigning values to it
@@ -263,7 +263,7 @@ def _check_doc_field_not_none(field_name, doc):
263263 stacked : tf .Tensor = tf .stack (tf_stack )
264264 tensor_columns [field_name ] = TensorFlowTensor (stacked )
265265
266- elif issubclass (field_type , AbstractTensor ):
266+ elif safe_issubclass (field_type , AbstractTensor ):
267267 if first_doc_is_none :
268268 _verify_optional_field_of_docs (docs )
269269 tensor_columns [field_name ] = None
@@ -291,7 +291,7 @@ def _check_doc_field_not_none(field_name, doc):
291291 val = getattr (doc , field_name )
292292 cast (AbstractTensor , tensor_columns [field_name ])[i ] = val
293293
294- elif issubclass (field_type , BaseDoc ):
294+ elif safe_issubclass (field_type , BaseDoc ):
295295 if first_doc_is_none :
296296 _verify_optional_field_of_docs (docs )
297297 doc_columns [field_name ] = None
@@ -307,7 +307,7 @@ def _check_doc_field_not_none(field_name, doc):
307307 tensor_type = self .tensor_type
308308 )
309309
310- elif issubclass (field_type , AnyDocArray ):
310+ elif safe_issubclass (field_type , AnyDocArray ):
311311 if first_doc_is_none :
312312 _verify_optional_field_of_docs (docs )
313313 docs_vec_columns [field_name ] = None
@@ -362,7 +362,7 @@ def validate(
362362 return value
363363 elif isinstance (value , DocList ):
364364 if (
365- issubclass (value .doc_type , cls .doc_type )
365+ safe_issubclass (value .doc_type , cls .doc_type )
366366 or value .doc_type == cls .doc_type
367367 ):
368368 return cast (T , value .to_doc_vec ())
@@ -481,7 +481,7 @@ def _set_data_and_columns(
481481 # set data and prepare columns
482482 processed_value : T
483483 if isinstance (value , DocList ):
484- if not issubclass (value .doc_type , self .doc_type ):
484+ if not safe_issubclass (value .doc_type , self .doc_type ):
485485 raise TypeError (
486486 f'{ value } schema : { value .doc_type } is not compatible with '
487487 f'this DocVec schema : { self .doc_type } '
@@ -491,7 +491,7 @@ def _set_data_and_columns(
491491 ) # we need to copy data here
492492
493493 elif isinstance (value , DocVec ):
494- if not issubclass (value .doc_type , self .doc_type ):
494+ if not safe_issubclass (value .doc_type , self .doc_type ):
495495 raise TypeError (
496496 f'{ value } schema : { value .doc_type } is not compatible with '
497497 f'this DocVec schema : { self .doc_type } '
0 commit comments