enthought / traits

Observable typed attributes for Python classes
Other
438 stars 85 forks source link

Proposal: A richer structure for Python-side fast validators #675

Open corranwebster opened 4 years ago

corranwebster commented 4 years ago

Currently, fast validators are specified by a tuple, the first value of which is the validator type, and the subsequent items are additional values to be interpreted by the ctraits.c machinery for that validator type. The exact contents of the tuple are not standardized, and in the cases of some are rather obtuse (eg. coercible type checks, which has two sub-lists embedded in the tuple, with a None value as a terminator of the first list, rather than, say, a tuple with tuples in it).

Adding some richer structure would help here:

In general, the code would be much more readable on the python side if we could write something like:

float_fast_validate = CoercingFastValidator(
    allow_none=False,
    base_types=(float, floating),
    coercible_types=(int, integer),
)
corranwebster commented 4 years ago

Note that this would require new validation constants for the new structures and to keep the old validators around for a while, or we would break pickle loading of old traits.