From f1c4cfea2ccbc392521c12d8927519de12ca76f2 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Fri, 23 Sep 2016 09:43:56 -0700 Subject: [PATCH] Remove implementation of `__getslice__` `__getslice__` has been Deprecated since Python 2.0 and is removed in Python 3. See https://docs.python.org/2/reference/datamodel.html#object.__getslice__ Unfortunately, Python 2 will still dispatch to `__getslice__` over `__getitem__`, See http://bugs.python.org/issue2041, which causes Warnings when running with `-3` in 2.7. --- _pytest/_code/source.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/_pytest/_code/source.py b/_pytest/_code/source.py index 2d55cd07f..846e3cced 100644 --- a/_pytest/_code/source.py +++ b/_pytest/_code/source.py @@ -60,16 +60,13 @@ class Source(object): else: if key.step not in (None, 1): raise IndexError("cannot slice a Source with a step") - return self.__getslice__(key.start, key.stop) + newsource = Source() + newsource.lines = self.lines[key.start:key.stop] + return newsource def __len__(self): return len(self.lines) - def __getslice__(self, start, end): - newsource = Source() - newsource.lines = self.lines[start:end] - return newsource - def strip(self): """ return new source object with trailing and leading blank lines removed.