Created
March 29, 2018 09:09
-
-
Save cleac/6e9810283636c180014f2b1c27d11e95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.7.12 (default, Dec 4 2017, 14:50:18) | |
[GCC 5.4.0 20160609] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from trafaret_validator import TrafaretValidator | |
>>> import trafaret as t | |
>>> class T1(TrafaretValidator): | |
... id = t.Int() | |
... | |
>>> x = T1(id=1) | |
>>> x.test = 1 | |
>>> x | |
<TrafaretValidator is-data-valid=True data={'id': 1} errors={}> | |
>>> x.test = t.Int() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "trafaret_validator/validator.py", line 59, in __setattr__ | |
self._trafaret = t.Dict(self._validators) | |
File "trafaret_validator/validator.py", line 59, in __setattr__ | |
self._trafaret = t.Dict(self._validators) | |
File "trafaret_validator/validator.py", line 54, in __setattr__ | |
raise AttributeError('Cannot reassign validator.') | |
AttributeError: Cannot reassign validator. | |
>>> x\ | |
... | |
KeyboardInterrupt | |
>>> x | |
<TrafaretValidator is-data-valid=True data={'id': 1} errors={}> | |
>>> T1 | |
<T1 trafaret=<Dict(<Key "id" <Int>>)>> | |
>>> T1._validators | |
{'test': <Int>, 'id': <Int>, '_trafaret': <Dict(<Key "id" <Int>>, <Key "test" <Int>>)>} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment