[issue2041] __getslice__ still called
Stefan Seefeld added the comment: Mark, thanks for the quick follow-up. OK, i now understand the situation better. The documentation I had read originally didn't talk about special-casing built-in objects. (And since I want to extend a tuple, I do have to override __getslice__ since I want to make sure the returned object still has the derived type.) Yes, I believe this issue can be closed as invalid. (Though I believe the docs could be a bit more clear about this.) Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2041 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2041] __getslice__ still called
Mark Dickinson added the comment: I think the docs do a good job of explaining this; in particular, they say, in http://docs.python.org/dev/reference/datamodel.html#special-method- names: However, built-in types in CPython currently still implement __getslice__(). and explain that __getslice__ is used only to implement the form a[i:j], and falls back to __getitem__ if __getslice__ is not implemented. Getting rid of __getslice__ for builtin types in Python 2.x is probably one of those things that would break backwards compatibility. And leaving it in is pretty harmless. To avoid surprises, don't implement __getslice__ in your own classes. But note that __getslice__ and friends are gone in Python 3.0. I'd recommend closing this as invalid, but I'll wait for a second opinion. -- nosy: +marketdickinson __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2041 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2041] __getslice__ still called
New submission from Stefan Seefeld: The python documentation states that since python 2.0 __getslice__ is obsoleted by __getitem__. However, testing with python 2.3 as well as 2.5, I find the following surprising behavior: class Tuple(tuple): def __getitem__(self, i): print '__getitem__', i def __getslice__(self, i): print '__getslice__', i t = Tuple() t[0] # __getitem__ called with type(i) == int t[0:2] # __getslice__ called with type(i) == slice t[0:2:1] # __getitem__ called with type(i) == slice -- components: Interpreter Core messages: 62162 nosy: stefan severity: major status: open title: __getslice__ still called type: behavior versions: Python 2.3, Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2041 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2041] __getslice__ still called
Mark Dickinson added the comment: Well, documentation patches are always welcome, I believe :) If you can point to a particular place in the documentation and suggest alternative (or extra) wording that might help, post it here and I'll deal with it. -- resolution: - invalid status: open - closed __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2041 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com