-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
When running the inference script, I encounter an error in utils/misc.py on the line asdict(obj).items(). The error message indicates that asdict is not defined. I realized that the asdict function from the dataclasses module was not imported. I added dataclasses.asdict(obj).items() at the beginning to resolve this.
However, as mentioned in the previous comment, this solution does not work for NamedTuple instances. Therefore, I modified the code to differentiate between dataclass and NamedTuple instances. The final code looks like this:
if isinstance(obj, Mapping):
return ty((k, map_fields(func, v, only_type)) for (k, v) in obj.items())
elif dataclasses.is_dataclass(obj):
# Dataclass
return ty(
**{k: map_fields(func, v, only_type) for (k, v) in dataclasses.asdict(obj).items()}
)
else:
# NamedTuple
return ty(
**{k: map_fields(func, v, only_type) for (k, v) in obj._asdict().items()}
)
Metadata
Metadata
Assignees
Labels
No labels