Skip to content

Commit 24ca4f6

Browse files
alexfiklinducer
authored andcommitted
feat: support dataclass subclassing in decorator
1 parent a5a4277 commit 24ca4f6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

arraycontext/container/dataclass.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ def _get_annotated_fields(cls: type) -> Sequence[_Field]:
163163
from inspect import get_annotations
164164

165165
result = []
166-
cls_ann: Mapping[str, type] | None = None
166+
field_name_to_type: Mapping[str, type] | None = None
167167
for field in fields(cls):
168168
field_type_or_str = field.type
169169
if isinstance(field_type_or_str, str):
170-
if cls_ann is None:
171-
cls_ann = get_annotations(cls, eval_str=True)
170+
if field_name_to_type is None:
171+
field_name_to_type = {}
172+
for subcls in cls.__mro__[::-1]:
173+
field_name_to_type.update(get_annotations(subcls, eval_str=True))
172174

173-
field_type = cls_ann[field.name]
175+
field_type = field_name_to_type[field.name]
174176
else:
175177
field_type = field_type_or_str
176178

0 commit comments

Comments
 (0)