Collections of non-arbitrary objects ?

Paddy paddy3118 at googlemail.com
Sat Jun 23 16:52:22 EDT 2007


On Jun 23, 6:45 pm, walterbyrd <walterb... at iname.com> wrote:
> On Jun 22, 11:43 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> wrote:
>
> > Can you help us understand, by showing a use case that would in your
> > estimation be improved by the feature you're describing?
>
> Suppose you are sequentially processing a list with a routine that
> expects every item to be of a certain type. Something in the list that
> doesn't conform to the type could give you unexpected results, maybe
> crash your application.
>
> In python, as far as I know, there is nothing built into the language
> to keep any type of item from being included in a list - or any such
> structure. To me, that seems like a potentially vulnerability.
> Especially since variables in python do not have to be explicitly
> assigned - another variable that points to the same thing, could
> change the data that a variable points to.

Reminds me a bit of that (awful) sketch:
  Patient: Doctor doctor it hurts if I do that.
  Doctor:  Well don't do that then.

The data for the list should have been checked when it entered
your program. It is up to you to then only stuff the list with
data expected by the routine. If you don't then Python will most
likely throw a runtime exception, but it is up to you to trust
your co-workers on the project.

- Paddy




More information about the Python-list mailing list