Fatal1ty / mashumaro

Fast and well tested serialization library
Apache License 2.0
758 stars 45 forks source link

Comprehension inlining on Python 3.12.0rc1 breaks some tests #152

Closed Fatal1ty closed 1 year ago

Fatal1ty commented 1 year ago

Description

Some tests are failed on Python 3.12.0rc1 and the root cause is the bug in comprehension inlining:

What I Did

from dataclasses import dataclass
from mashumaro import DataClassDictMixin

@dataclass
class DataClass(DataClassDictMixin):
    x: dict[int, int] | list[float]

print(DataClass.from_dict({"x": {"1.1": "2.2"}}))  # will raise InvalidFieldValue

On Python <3.12 this code works as expected and prints: DataClass(x=[1.1]). To fix this issue we can use different names for keys and values inside comprehensions or wait for the bug fix in CPython itself before the final release.

Fatal1ty commented 1 year ago

This issue is fixed in python 3.12.0rc2