[Zope-Coders] Keyword Indexes misbehaving?

Chris Withers chrisw@nipltd.com
Wed, 05 Mar 2003 13:00:47 +0000


Casey Duncan wrote:
> 
> 1. If its a string, wrap it in a tuple and index it.
> 2. If its a list or tuple or other sequence, just index it.
> 3. If its something else, fail silently.

3 blows :-(

I always assumed that it was:

1. if it's not something sequence-ish, wrap it in a tuple and proceed to step 2
2. index the sequence-ish thing.

Now, unfortunately (for this scenario), strings _are_ sequences in python, and 
we don't want to be idnexing things like:

['f','r','e','d']

So, how this?

1. If a string, wrap in a tuple and go to step 3
2. If not a sequence, wrap in a tuple and go to step 3
3. Index the sequence.

> I fear that the code you suggested breaks number 2, since it rewraps "other 
> sequences" into a tuple. I don't know how many apps depend on this behavior.

I don't think that matters, it's wrong. It should only wrap strings and 
non-sequences.

cheers,

Chris