From 93832e1048f8faf0b1c3d1d5d5c382e44d1464ff Mon Sep 17 00:00:00 2001 From: Alexander Tikhonov Date: Wed, 8 Jun 2022 12:41:00 +0300 Subject: [PATCH] Fix using generics inside DataClassMessagePackMixin dataclasses --- mashumaro/core/meta/builder.py | 2 +- tests/test_dialect.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mashumaro/core/meta/builder.py b/mashumaro/core/meta/builder.py index fff38644..4cb8dcec 100644 --- a/mashumaro/core/meta/builder.py +++ b/mashumaro/core/meta/builder.py @@ -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" diff --git a/tests/test_dialect.py b/tests/test_dialect.py index fb81e8c1..46985ffa 100644 --- a/tests/test_dialect.py +++ b/tests/test_dialect.py @@ -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(): @@ -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