diff options
author | Michael Blahay <mblahay@users.noreply.github.com> | 2019-05-07 21:41:06 (GMT) |
---|---|---|
committer | Mark Shannon <mark@hotpy.org> | 2019-05-07 21:41:06 (GMT) |
commit | b1c3167c232c36ed3543ca351ff10c613639b5f5 (patch) | |
tree | 93ea768476af4da82e8697317a131de34c6a2772 /Lib/collections/__init__.py | |
parent | ca87eebb22d202c33f3317cbf85059cadc64fa9f (diff) | |
download | cpython-b1c3167c232c36ed3543ca351ff10c613639b5f5.zip cpython-b1c3167c232c36ed3543ca351ff10c613639b5f5.tar.gz cpython-b1c3167c232c36ed3543ca351ff10c613639b5f5.tar.bz2 |
bpo-27639: Correct return type for UserList slicing operation (#13169)
* BPO-27639: Correct return type for UserList slicing operation
Added logic to __getitem__ magic method for UserList to ensure that the return
type matches that of self.
Diffstat (limited to 'Lib/collections/__init__.py')
-rw-r--r-- | Lib/collections/__init__.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index e6cafb3..706907a 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1085,7 +1085,11 @@ class UserList(_collections_abc.MutableSequence): return other.data if isinstance(other, UserList) else other def __contains__(self, item): return item in self.data def __len__(self): return len(self.data) - def __getitem__(self, i): return self.data[i] + def __getitem__(self, i): + if isinstance(i, slice): + return self.__class__(self.data[i]) + else: + return self.data[i] def __setitem__(self, i, item): self.data[i] = item def __delitem__(self, i): del self.data[i] def __add__(self, other): |