enthought/traits — pull request #205 by itziakos (2014-10-06 18:41:59+00:00)
Title: Feature/validated tuple

This PR adds a new Tuple trait that supports custom validation for the field values in addition to the individual field validation.

```python

>>> from traits.api import Int, HasStrictTraits, ValidatedTuple
>>>
>>> class MyClass(HasStrictTraits):
... value_range = ValidatedTuple(Int(0), Int(1), validation=lambda x: x[0] < x[1])
...
>>>
>>> a = MyClass()
>>> a.value_range
(0, 1)
>>> a.value_range = (2, 1)
Traceback (most recent call last):
File "", line 1, in
File "c:\users\itziakos\projects\meta-geophysics\geocanopy\geophysics\util\validated_tuple.py", line 43, in validate
self.error(object, name, value)
File "C:\Users\itziakos\Projects\traits\traits\trait_handlers.py", line 172, in error
value )
TraitError: The 'value_range' trait of a MyClass instance must be a tuple of the form: (an integer (int or long), an integer (int or long)) that passes custom validation, but a value of (2, 1) was specified.
>>> a.value_range = (1, 2)
>>> a.value_range
(1, 2)
>>>
```