Closed ant5 closed 6 years ago
can You try trafaret.Type(object)
?
try trafaret.Any
We probably have not the best docs, so will not close this now and will treat it as doc issue.
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'
check_and_return
, check_value
, transform
is internal methods for trafarets. Use just direct call (value)
or check(value)
. Trafarets are callables.
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.
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()