Purpose of Python Type Checking?
Terry Reedy
tjreedy at udel.edu
Sun Jan 26 23:13:29 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?
Possibilities (not necessarily disjoint):
1. Habit carried over or based on experience with other languages.
2. Situation-specific need such as changing behavior depending on
type.
3. Application of belief in "look-before-you-leap" rather than
"try-it-and-see".
4. Being careful in life- or mission-critical application.
> Yes, I know its to "ensure" that parameters are valid but doesn't
that
> defeat the whole purpose of one of Python's main feature?
Polymorphism
> and code reuse. Who cares if a parameter is not of type(X), as long
as
> it has the methods and member variables necessary. If the parameter
is
> missing stuff, then an exception is thrown.
>
> 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.
There have also been past postings advising against it, especially by
Alex Martelli, citing just the reason you gave above.
> So, is there a good reason I should be using it too?
Your decision.
Terry J. Reedy
More information about the Python-list
mailing list