[issue27639] UserList.__getitem__ doesn't account for slices

Michael Blahay report at bugs.python.org
Mon May 6 16:52:21 EDT 2019


Michael Blahay <mblahay at gmail.com> added the comment:

The root cause of this issue seems to be the failure to implement type usage in __getitem__ when the deprecated __getslice__ was removed. This is why slicing worked correctly in 2.7, but not the 3.x versions.

In 3.8, the __getitem__ method is used to create the slice, but here we can see that all it does is pass the task to data, which is of type list and then fails to convert the result to the correct type.

  def __getitem__(self, i): return self.data[i]

Using other methods as examples, the fix should look like this:

  def __getitem__(self, i): return self.__class__(self.data[i])

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27639>
_______________________________________


More information about the Python-bugs-list mailing list