Message29173
| Author |
collinwinter |
| Recipients |
| Date |
2006年07月13日.19:25:19 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
Consider the following code:
>>> class badstr(str):
... def __len__(self):
... return 6
... def __getitem__(self, index):
... return "a"
...
>>> filter(None, badstr("bbb"))
'aaa'
I would have expected the answer to be 'aaaaaa'.
The cause for this is that
Python/bltinmodule.c:filter{string,unicode,tuple} all
call PyString_Size (or the appropriate equivalent),
even if the sequence is a subclass of one of these
types. This bypasses any overloading of __len__ done by
the subclass, as demonstrated above.
If filter() is going to respect the subclass's
__getitem__ overload, it should also respect
overloading of __len__. The attached patch corrects this.
|
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 14:41:20 | admin | link | issue1522016 messages |
| 2007年08月23日 14:41:20 | admin | create |
|