From a0f169cde878f08c2873b0cdf42118439113a96f Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Wed, 2 Oct 2013 22:06:54 +1000 Subject: Close #19078: memoryview now supports reversed Patch by Claudiu Popa --- Lib/test/test_memoryview.py | 9 +++++++++ Misc/NEWS | 4 ++++ Objects/memoryobject.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index ee6b15a..ffd4f58 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -352,6 +352,15 @@ class AbstractMemoryTests: self.assertIs(wr(), None) self.assertIs(L[0], b) + def test_reversed(self): + for tp in self._types: + b = tp(self._source) + m = self._view(b) + aslist = list(reversed(m.tolist())) + self.assertEqual(list(reversed(m)), aslist) + self.assertEqual(list(reversed(m)), list(m[::-1])) + + # Variations on source objects for the buffer: bytes-like objects, then arrays # with itemsize > 1. # NOTE: support for multi-dimensional objects is unimplemented. diff --git a/Misc/NEWS b/Misc/NEWS index 9cf8ada..71de0bb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Projected release date: 2013-10-20 Core and Builtins ----------------- +- Issue #19078: memoryview now correctly supports the reversed builtin + (Patch by Claudiu Popa) + + Library ------- diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index abd069b..e57af18 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -2402,7 +2402,7 @@ static PyMappingMethods memory_as_mapping = { /* As sequence */ static PySequenceMethods memory_as_sequence = { - 0, /* sq_length */ + (lenfunc)memory_length, /* sq_length */ 0, /* sq_concat */ 0, /* sq_repeat */ (ssizeargfunc)memory_item, /* sq_item */ -- cgit v0.12