@@ -335,19 +335,23 @@ def typing_to_runner_api(self, type_: type) -> schema_pb2.FieldType:
335335 atomic_type = PRIMITIVE_TO_ATOMIC_TYPE [int ])))
336336
337337 elif _safe_issubclass (type_ , Sequence ) and not _safe_issubclass (type_ , str ):
338- element_type = self .typing_to_runner_api (_get_args (type_ )[0 ])
339- return schema_pb2 .FieldType (
340- array_type = schema_pb2 .ArrayType (element_type = element_type ))
338+ arg_types = _get_args (type_ )
339+ if len (arg_types ) > 0 :
340+ element_type = self .typing_to_runner_api (arg_types [0 ])
341+ return schema_pb2 .FieldType (
342+ array_type = schema_pb2 .ArrayType (element_type = element_type ))
341343
342344 elif _safe_issubclass (type_ , Mapping ):
343345 key_type , value_type = map (self .typing_to_runner_api , _get_args (type_ ))
344346 return schema_pb2 .FieldType (
345347 map_type = schema_pb2 .MapType (key_type = key_type , value_type = value_type ))
346348
347349 elif _safe_issubclass (type_ , Iterable ) and not _safe_issubclass (type_ , str ):
348- element_type = self .typing_to_runner_api (_get_args (type_ )[0 ])
349- return schema_pb2 .FieldType (
350- array_type = schema_pb2 .ArrayType (element_type = element_type ))
350+ arg_types = _get_args (type_ )
351+ if len (arg_types ) > 0 :
352+ element_type = self .typing_to_runner_api (arg_types [0 ])
353+ return schema_pb2 .FieldType (
354+ array_type = schema_pb2 .ArrayType (element_type = element_type ))
351355
352356 try :
353357 if LogicalType .is_known_logical_type (type_ ):
@@ -631,7 +635,8 @@ def schema_from_element_type(element_type: type) -> schema_pb2.Schema:
631635 if isinstance (element_type , row_type .RowTypeConstraint ):
632636 return named_fields_to_schema (element_type ._fields )
633637 elif match_is_named_tuple (element_type ) or match_is_dataclass (element_type ):
634- if hasattr (element_type , row_type ._BEAM_SCHEMA_ID ):
638+ # schema id does not inherit from base classes
639+ if row_type ._BEAM_SCHEMA_ID in element_type .__dict__ :
635640 # if the named tuple's schema is in registry, we just use it instead of
636641 # regenerating one.
637642 schema_id = getattr (element_type , row_type ._BEAM_SCHEMA_ID )
0 commit comments