Re: overriding validate_python (and similar methods) in validators
Ian Bicking <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
(catching up on emails I forgot about) Jacob Smullyan wrote: > Hello. I'm a bit new to FormEncode, so pardon me if I'm bringing up > an old chestnut or need to be set straight about something. > > I recently had a bunch of custom validators, subclassing > FancyValidator or one of its subclasses (Regex, for instance), and > then I found a bug in one of them -- I overrode validate_python but > didn't call the same method on the superclass, so didn't get the > complete validation. (I believe this was a Regex subclass.) So I > went through my validators and made sure that whenever I wrote a > validate_python method, I called the corresponding superclass method. > Then I tried running it, and whoah! for some but not all of the > validators, this gave rise to an error, because validate_python in > FancyValidator is None. > > I take it that the reason FormEncode allows validate_python et al to > have the value of None is to support a declarative programming style. > But to my mind the use of this feature in FancyValidator, a base > class, makes the interface it presents rather confusing and > unpredictable, and, I think, results in an excessively leaky > abstraction. Couldn't these methods be defined there as noops, or > would that have side-effects I'm unaware of? It's purely for efficiency, so if the method isn't defined it doesn't get called. It's really only meant to be called from FancyValidator.(to|from)_python. Though now that you mention it, there's no very good way to tell the difference between a validator that overrides this method (and hence you have to call the superclass), and one that doesn't (and hence you can't call the superclass). I've changed this in the trunk. -- Ian Bicking | [email protected] | http://blog.ianbicking.org ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642