import collections
import typing
from dataclasses import dataclass
from typing import OrderedDict, Type
from typing_extensions import Annotated
from mashumaro.mixins.json import DataClassJSONMixin
def kwtypes(**kwargs) -> OrderedDict[str, Type]:
"""
This is a small helper function to convert the keyword arguments to an OrderedDict of types.
.. code-block:: python
kwtypes(a=int, b=str)
"""
d = collections.OrderedDict()
for k, v in kwargs.items():
d[k] = v
return d
@dataclass
class test(DataClassJSONMixin):
b: typing.List[Annotated[int, "parquet"]]
c: typing.Dict[str, Annotated[int, kwtypes(Name=str, Age=int)]]
Description
TypeError is raised when using
collections.OrderedDict
object as annotation intyping_extensions.Annotated
on python<3.9:Originally reported by @hhcs9527: https://github.com/Fatal1ty/mashumaro/pull/134#issuecomment-1679931209 Related to:
133
What I Did