Skip to content

Conversation

@litwisha
Copy link

@litwisha litwisha commented Aug 21, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants