You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It couples validators to the instance's __dict__ and so therefore requires extensibility to happen through inheritance.
E.g., if Foo is an IValidator that uses ValidatorMixin and you want to add your own totally cool validators that extend Foo's validators, you need to inherit.
Instead, it should be possible to wrap a validator, and / or to separate ValidatorMixin's implementation of all the convenience method implementations (validate, is_valid, etc.) from its implementation of iter_errors.
Modifying IValidator to specify a dict where validators live might be appropriate.
E.g. specify a validators attribute that should map validators to validator functions ({"type" : validate_type}) that will be called with an IValidator and all the stuff it gets called with now. This would solve a small side problem which is that validators currently sorta have to be valid identifiers.
Then ValidatorMixin.iter_errors would delegate to ValidatorMixin.validator_for (see e.g. dfcd6e8 which has been temporarily reverted), for which the default implementation would just be return self.validators.get(validator)
The docs should be updated to specifically discourage any inheritance anymore.
Just so I record this on paper for future reference, though I'll probably implement it tomorrow or so, the new API for making validators will probably look lke
It couples validators to the instance's
__dict__
and so therefore requires extensibility to happen through inheritance.E.g., if
Foo
is anIValidator
that usesValidatorMixin
and you want to add your own totally cool validators that extendFoo
's validators, you need to inherit.Instead, it should be possible to wrap a validator, and / or to separate
ValidatorMixin
's implementation of all the convenience method implementations (validate
,is_valid
, etc.) from its implementation ofiter_errors
.Modifying
IValidator
to specify a dict where validators live might be appropriate.E.g. specify a
validators
attribute that should map validators to validator functions ({"type" : validate_type}
) that will be called with anIValidator
and all the stuff it gets called with now. This would solve a small side problem which is that validators currently sorta have to be valid identifiers.Then
ValidatorMixin.iter_errors
would delegate toValidatorMixin.validator_for
(see e.g. dfcd6e8 which has been temporarily reverted), for which the default implementation would just bereturn self.validators.get(validator)
The docs should be updated to specifically discourage any inheritance anymore.
@gazpachoking thoughts?
The text was updated successfully, but these errors were encountered: