How to validate the __init__ parameters

Phlip phlip2005 at
Mon Jan 4 19:53:43 CET 2010

Steve Holden  <steve at> wrote:

> What's the exact reason for requiring that a creator argument be of a
> specific type? So operations on the instances don't go wrong? Well, why
> not just admit that we don't have control over everything, and just *let
> things go wrong* when the wrong type is passed?

Because some interfaces are "public", meaning visible within their own little 
arena of modules, and some interfaces are "published", meaning visible to other 
packages. Encapsulation is hierarchical - this is just a "small things go inside 
big things" situation. The higher an interface's level, the more "published" it is.

Published interfaces should fail as early and clearly as possible if they are 
going to fail. The obvious example here is an interface that fails and prints a 
message telling a newbie how to call the package the right way. But that newbie 
could be you!

(And don't forget the wall-to-wall unit tests, too;)


More information about the Python-list mailing list