trafaret_forked icon indicating copy to clipboard operation
trafaret_forked copied to clipboard

trafaret inner calls

Open litwisha opened this issue 8 years ago • 0 comments

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

litwisha avatar Aug 21 '17 17:08 litwisha