[Python-Dev] Approaches to argument type-checking
benjamin at python.org
Thu Mar 12 04:29:34 CET 2009
2009/3/11 Tennessee Leeuwenburg <tleeuwenburg at gmail.com>:
> Is there a general strategy used in Python development which I should be
> aware of? i.e. is it customary to type-check every argument of an interface
> method? Or is it customary not to perform type checking up-front and simply
> allow the exception to occur deeper in the code? Are there performance
> issues surrounding defensive programming?
Generally we avoid checking types at all in Python because of ducking
typing. The C interface must check types because they have to
translate to the C level equivalents.
If tests are failing from a C implementation on a Python
implementation because of extensive type checking, I would be tempted
to mark those tests as implementation details.
However, in the case of this specific issue, I think rejecting bytes
purposefully is good because it avoids programming errors.
More information about the Python-Dev