dataclasses-json
dataclasses-json copied to clipboard
UserWarning: Unknown type typing.Tuple [bug]
Steps to reproduce
Run the following tests by pytest:
import warnings
from dataclasses import dataclass
from typing import Tuple, List
from dataclasses_json import DataClassJsonMixin
@dataclass
class Foo(DataClassJsonMixin):
bar: List[Tuple[str, int]]
def test_many_foo_from_dict():
foos = [
{
'bar': [
["item1", 1],
["item2", 2],
]
}
]
Foo.schema().load(foos, many=True)
Actual result
There is a warning:
C:\Users\user\.virtualenvs\project-cKk0Zhor\lib\site-packages\dataclasses_json\mm.py:270: UserWarning: Unknown type typing.Tuple[str, int] at Foo.bar: typing.List[typing.Tuple[str, int]] It's advised to pass the correct marshmallow type to `mm_field`.
Expected result
No warnings.
I think this is because there is no mapping of the Python type tuple to fields.Tuple in https://github.com/lidatong/dataclasses-json/blob/3dc59e01ccdfec619ee4e4c3502b9759b67c3fa8/dataclasses_json/mm.py#L116-L134.
Before the lookup, this is called: https://github.com/lidatong/dataclasses-json/blob/3dc59e01ccdfec619ee4e4c3502b9759b67c3fa8/dataclasses_json/mm.py#L251
In case of a typing.Tuple, __origin__ is defined and points to tuple (the Python type).
However, naively plugging it in breaks.