Closed naegelejd closed 8 months ago
The source of recursion (shown in stacktrace above) is at the bottom of the generated types.py
:
AliasedRecord = GenericRecord[T]
AliasedOpenGeneric = AliasedRecord[T]
AliasedClosedGeneric = AliasedRecord[str]
def _mk_get_dtype():
dtype_map: dict[typing.Union[type, types.GenericAlias], typing.Union[np.dtype[typing.Any], typing.Callable[[tuple[type, ...]], np.dtype[typing.Any]]]] = {}
get_dtype = _dtypes.make_get_dtype_func(dtype_map)
dtype_map[GenericRecord] = lambda type_args: np.dtype([('v', get_dtype(type_args[0]))], align=True)
dtype_map[AliasedRecord] = lambda type_args: get_dtype(types.GenericAlias(GenericRecord, (type_args[0],)))
dtype_map[AliasedOpenGeneric] = lambda type_args: get_dtype(types.GenericAlias(AliasedRecord, (type_args[0],)))
dtype_map[AliasedClosedGeneric] = get_dtype(types.GenericAlias(AliasedRecord, (str,)))
return get_dtype
The problem is that AliasedOpenGeneric == AliasedRecord
, so we overwrite the dtype_map
lambda, recursing without ever resolving to the final dtype of GenericRecord
.
I'll try two quick fixes:
dtype_map
Using yardl commit ae9b826 with the following model:
To reproduce, generate Python for this model, then import the generated Python module. The module won't import, failing with the following error:
For this particular model, reordering the aliases as shown below can eliminate the error, but this is a confusing limitation for the user.