TypeError: Ellipsis is not a dataclass and cannot be turned into one.
from dataclasses import field
from decimal import Decimal
from typing import Tuple
from marshmallow_dataclass import dataclass
@dataclass(frozen=True)
class Signal:
fields: Tuple[Decimal, ...] = field(default_factory=list)
This ellipsis means that all values in fields have Decimal type.
Unfortunately, marshmallow does not seem to support variable length Tuple.
As per the documentation:
class marshmallow.fields.Tuple: A tuple field, composed of a fixed number of other Field classes or instances
@sloria : Any opinion ?
How to make frozen dataclass with a list?
How to make frozen dataclass with a list?
I think your best bet for now is to create your own VariableLengthTuple field. See marshmallow's documentation on custom fields.
Then, you can have:
@dataclass(frozen=True)
class Signal:
fields: Tuple[Decimal, ...] = field(
default_factory=tuple,
metadata = {"marshmallow_field":VariableLengthTuple()})
desert (a fork of marshmallow_dataclass) added support for variadic tuples. The PR would be worth evalutating: https://github.com/python-desert/desert/pull/17
@sloria : Would you consider adding VariadicTuple to marshmallow itself?
We just ran into this as well. Support for variadic tuples would be cool but in the end the workaround is pretty simple (just using List now).
I'm not sure when/how, but it seems to me like this is now resolved (I tried with version 8.5.10). Can anyone else confirm?
I'm not sure when/how, but it seems to me like this is now resolved (I tried with version 8.5.10). Can anyone else confirm?
This was indeed fixed in #221, which is included as of release 8.5.10. (I was working on fixing #181 and independently noticed and fixed this issue as well, unaware of this ticket.)