Type checking in python?

Paul Prescod paul at prescod.net
Thu Jul 20 18:29:18 EDT 2000


Samuel Scarano wrote:
> 
> (First of all, I just wanted take a moment to thank Paul Prescod for his
> very informative response to my post in this thread.)

Glad to help. I'll poke my nose in one more time:

> Fair enough. I agree that implementing the necessary methods is the most
> practical solution in this case -- and in many others. However, I think that
> the obvious objection to this approach would be that because there *are* no
> explicit interfaces in python, you can't create a class that's guaranteed to
> work wherever another class works just by implementing the same methods. 

Okay, but that was always a false guarantee. You can implement the right
interface but blow up on negative numbers, or even numbers or when the
day of the month is a prime number.

It is at least arguable that the chances of a type signature problem
slipping through a rigorous test suite is pretty small. Now what if you
use the time you saved setting up the interface hierarchy for improving
the test suite. You might find BOTH your type signature problems AND
more subtle logic problems.

-- 
 Paul Prescod - Not encumbered by corporate consensus
"Hardly anything more unwelcome can befall a scientific writer than 
having the foundations of his edifice shaken after the work is 
finished.  I have been placed in this position by a letter from 
Mr. Bertrand Russell..." 
 - Frege, Appendix of Basic Laws of Arithmetic (of Russell's Paradox)





More information about the Python-list mailing list