Deepwalker / trafaret

Ultimate transformation library that supports validation, contexts and aiohttp.
http://trafaret.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
177 stars 31 forks source link

How to work with tuples in general? #23

Closed ShT3ch closed 6 years ago

ShT3ch commented 6 years ago

Hello. Here the case.

Maintainers of aiozmq library recommend to use trafaret for type checking. But also aiozmq's internals convert all lists to tuples while passing messages for RPC.

Trafaret's tuples take implicit types as parameter, but I'm not able just to receive tuple instead of list using trafaret.

For example:

import trafaret

recieved_msg = (1,2,3,4,5)

trafaret.Tuple(trafaret.Int).check(recieved_msg)

raises an error DataError: {0: DataError(value must contain 1 items)}

I'm not able to use trafaret.List too. It checks isinstance(obj, list).

Can you suggest some workaround?

Deepwalker commented 6 years ago

Since it is too late to fix this in 1.x, I will check for Iterable in next release. Meanwhile you can use something like t.Type(tuple) & list & t.List(t.Int). It will check that we have a tuple, then convert to list and now t.List can work.