[Zope3-dev] Add function for schema validation in zope.schema

Benji York benji at zope.com
Mon Aug 20 09:52:50 EDT 2007


Wichert Akkerman wrote:
> That would be confusing though: I would expect the result of a method
> that checks validaty to return something that evaluates to True if
> everything is valid. Code like this just messes up my brain:
> 
>   if not zope.schema.validate(obj, IMySchema):
> 	  print "Everything validates correctly!"
> 
> to me that is very non-intuitive and looks like the if condition is
> incorrect.

Agreed.  I prefer to name boolean methods with an "is" prefix.  Then we 
would have

if zope.schema.isValid(obj, IMySchema):
     print 'valid'

and

if not zope.schema.isValid(...):
     print 'invalid'

That doesn't give any information about what is invalid though, I'd use 
a separate method for that.  Perhaps something like "getValidationErrors".
-- 
Benji York
Senior Software Engineer
Zope Corporation


More information about the Zope3-dev mailing list