Skip to content

Commit

Permalink
Fix using generics inside DataClassMessagePackMixin dataclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Jun 8, 2022
1 parent bc43c09 commit 93832e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mashumaro/core/meta/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def is_code_generation_option_enabled(self, option: str, cls=None) -> bool:
cls = self.cls
if option == ADD_DIALECT_SUPPORT:
# TODO: make inheritance for code_generation_options
for ancestor in cls.__mro__[-1:0:-1]:
for ancestor in get_type_origin(cls).__mro__[-1:0:-1]:
if (
type_name(ancestor)
== "mashumaro.mixins.msgpack.DataClassMessagePackMixin"
Expand Down
21 changes: 12 additions & 9 deletions tests/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ class Config(BaseConfig):

@dataclass
class MessagePackDataClass(DataClassMessagePackMixin):
b: bytes
bb: bytearray
dep: DataClassWithoutDialects
b_1: bytes
b_2: bytearray
dep_1: DataClassWithoutDialects
dep_2: GenericDataClassWithoutDialects[date]


def test_default_dialect():
Expand Down Expand Up @@ -890,14 +891,16 @@ def test_dialect_with_inheritance():
def test_msgpack_dialect_class_with_dependency_without_dialect():
dt = date(2022, 6, 8)
obj = MessagePackDataClass(
b=b"123",
bb=bytearray([4, 5, 6]),
dep=DataClassWithoutDialects(dt, 123),
b_1=b"123",
b_2=bytearray([4, 5, 6]),
dep_1=DataClassWithoutDialects(dt, 123),
dep_2=GenericDataClassWithoutDialects(dt, 123),
)
d = {
"b": b"123",
"bb": bytearray([4, 5, 6]),
"dep": {"dt": "2022-06-08", "i": 123},
"b_1": b"123",
"b_2": bytearray([4, 5, 6]),
"dep_1": {"dt": "2022-06-08", "i": 123},
"dep_2": {"dt": "2022-06-08", "i": 123},
}
encoded = msgpack_encoder(d)
assert obj.to_msgpack() == encoded
Expand Down

0 comments on commit 93832e1

Please sign in to comment.