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

Trafaret object to pass value as is #29

Closed ant5 closed 6 years ago

ant5 commented 6 years ago

Hello and thank you for your work fiirst of all.

I have a small suggestion to use trafaret in more uniform way. I have some data with assigned trafaret and some without constraints. So I have to do something like this: if data.trafaret: val = data.trafaret.check_and_return(rawval) else: val = rawval

If you'll kindly add an object something like "NoCheck" which will pass arguments out without any check it will be possible to always do: val = data.trafaret.check_and_return(rawval)

while data without constraints will be initialized as: data.trafaret = trafaret.NoCheck()

hellysmile commented 6 years ago

can You try trafaret.Type(object) ?

Deepwalker commented 6 years ago

try trafaret.Any

Deepwalker commented 6 years ago

We probably have not the best docs, so will not close this now and will treat it as doc issue.

ant5 commented 6 years ago

I've tried trafaret.Any(). But it seems no luck:

import trafaret tft = trafaret.Any() tft.check_and_return('aaa') Traceback (most recent call last): File "", line 1, in AttributeError: 'Any' object has no attribute 'check_and_return'

Deepwalker commented 6 years ago

check_and_return, check_value, transform is internal methods for trafarets. Use just direct call (value) or check(value). Trafarets are callables.

ant5 commented 6 years ago

Oh, I see. Thanks all. Also thank you for point me that trafaret is callable. Both solution works: import trafaret tft = trafaret.Any() tft('aaa') 'aaa' tft2 = trafaret.Type(object)

tft2('aaa') 'aaa'

I prefer trafaret.Any() for readability.

Thank you again. I enjoy to produce really beautifull code with this library.