[prev in list] [next in list] [prev in thread] [next in thread]
List: zope-coders
Subject: Re: [Zope-Coders] Patch for KeywordIndexes
From: Casey Duncan <casey () zope ! com>
Date: 2003-05-31 3:00:28
[Download RAW message or body]
All of the type tests in here are kludges.
How about something like this:
from types import StringType, UnicodeType
...
if (isinstance(newKeywords, StringType)
or isinstance(newKeywords, UnicodeType)): #Python 2.1 compat isinstance
return (newKeywords,)
else:
try:
newKeywords = tuple(newKeywords)
except TypeError:
# Not a sequence
return (newKeywords,)
else:
... uniqueify ...
or as a variation of your code:
if (isinstance(newKeywords, StringType)
or isinstance(newKeywords, UnicodeType)): #Python 2.1 compat isinstance
return (newKeywords,)
else:
unique = {}
try:
for k in newKeywords:
unique[k] = None
except TypeError:
# Not a sequence
return (newKeywords,)
else:
return unique.keys()
I know we're stuck with this dwim for bw compatibility, but I hope that we can
consent to simply require that the source be a sequence in future "keyword"
index implementations.
-Casey
On Friday 30 May 2003 07:13 pm, Sidnei da Silva wrote:
> On Fri, May 30, 2003 at 05:34:30PM -0400, Tres Seaver wrote:
> | On Fri, 2003-05-30 at 17:21, Sidnei da Silva wrote:
> | > If no one object (or if someone provides a better way to do this) I
> | > would like to apply the following patch for KeywordIndexes on
> | > 2_6-branch and HEAD. Its just completely annoying that this worked
> | > before, and now its so stupidly broken :(
> |
> | I don't think your patch works correctly: the test for "string-like" is
> | not the same as a test for iterability. As a check, try indexing an
> | object with a "string" property (instead of "lines" or "tokens"). I'll
> | bet you end up indexing each letter of the string as a "keyword".
>
> You're right. It needs to test for string-like *and* for
> iterability. Here's the fixed version.
>
> --
> Sidnei da Silva (dreamcatcher) <sidnei@x3ng.com.br>
> X3ng Web Technology <http://www.x3ng.com.br>
> GNU/Linux user 257852
> Debian GNU/Linux 3.0 (Sid) 2.4.20-powerpc ppc
>
> Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic