trafaret_forked
trafaret_forked copied to clipboard
trafaret inner calls
Basic trafarets should be called directly, instead of calling check method.
Reason:
method __call__ is an entrypoint to trafaret
If we need to redefine method __call__ in custom trafaret, and use this trafaret in t.Or or any other containers, then its method __call__ will never be called.
Example:
import trafaret as t
class CustomString(t.String):
def __call__(self, val, context=None):
print('hello')
return super().__call__(val, context)
Example = t.Or(CustomString(), t.Int())
Example('foo')
hello wil never be printed