Purpose of Python Type Checking?

A. Lloyd Flanagan alloydflanagan at attbi.com
Mon Jan 27 14:44:00 EST 2003


Mongryong <Mongryong at sympatico.ca> wrote in message news:<mailman.1043633328.27598.python-list at python.org>...
> Why do people use type checking in Python?  
> 
...
> 
> The reason I'm asking is because I don't use type checking at all but I
> ses a lot of other code use it.  So, is there a good reason I should be
> using it too?

Short answer: No!  I don't think I've yet seen a case where explicit
type-checking did anything but make code 'brittle' -- i.e. cause it to
fail when it receives a type that would have worked fine without the
type-check.

There are probably cases where you have to make an exception.  In that
case I'd recommend that, instead of forcing a parameter to have a type
that you know works, just make sure that it isn't a type you know
doesn't work.  Preserve the caller's freedom to pass you a type that
you didn't plan for, if it 'does the right thing.'




More information about the Python-list mailing list