Skip to content

Commit

Permalink
Support dict for dataclass_with_defaults (used by stateclass)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Apr 27, 2024
1 parent 37d6a89 commit e61bf29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mesop/dataclass_utils/dataclass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def dataclass_with_defaults(cls: Type[C]) -> Type[C]:
setattr(cls, name, field(default=False))
elif get_origin(type_hint) == list:
setattr(cls, name, field(default_factory=list))
elif get_origin(type_hint) == dict:
setattr(cls, name, field(default_factory=dict))
elif isinstance(type_hint, type):
setattr(
cls, name, field(default_factory=dataclass_with_defaults(type_hint))
Expand Down
1 change: 1 addition & 0 deletions mesop/dataclass_utils/dataclass_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WithPandasDataFrame:
@dataclass_with_defaults
class DataclassNoDefaults:
foo: int
dict: dict[str, str]


class UnannotatedClass:
Expand Down

0 comments on commit e61bf29

Please sign in to comment.