does lack of type declarations make Python unsafe?

Alex Martelli aleax at aleax.it
Tue Jun 17 12:15:26 EDT 2003


Terry Reedy wrote:
   ...
>> E.g., indexing blah[bloh] with an
>> invalid index value computed in variable bloh (invalid with respect
>> to the set of indices that container blah can accept) is, alas, far
>> from rare; but it's not a type-checking issue,
> 
> Depends on what you call a type.  A 'count' or a 'residue_class' is as
> much a mathematical 'type' as an 'int' (or a 'rat').

A 'type' that is checkable at compile-time is (at the very least)
a set whose membership needs to be fixed and known at compile-time.
(There may be other requirements, but this one is crucial;-).

"The set of acceptable keys/indices into 'blah' at this moment
(which depends on how big 'blah' is right now, etc etc)" is not
``a type'' in this sense.  So, if 'blah' is a std::vector<...>
in C++, a Vector in Java, a Python list, or basically any sort of
usable array/vector whose capacity can be determined at runtime,
then compile-time type checking just cannot substitute for runtime
checking of indices.


Alex





More information about the Python-list mailing list