Ofer Schwarz added the comment:

I'm working on this now (patch hopefully coming soon), and I've hit an 
interesting issue:
PySequence methods take care of negative indexes by adding +len before calling 
the subclass method (s.t. -1 becomes len-1 etc.). This means that if the 
subclass raises an exception with the index, it might be the wrong index.

This case only happens when index < -len, so when I talked it out with Larry he 
suggested just passing the original index to the subclass in this case. So for 
index >= 0 or index < -len the subclass will receive the actual index, and for 
-len <= index < 0 the subclass will get index+len.
That's a change in behavior, but I actually think it's a good one. The 
negative-index use case in PySequence is exactly intended for this [-len, 0) 
use case, and if some subclass wants to do something weird with negative 
indexes it'd probably want the actual argument anyway.

I'm writing my patch with this in it, but it might be worth discussing here if 
someone disagrees.

----------
nosy: +blackfawn

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18162>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to