summaryrefslogtreecommitdiff
path: root/Lib/test/test_enumerate.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2016-08-18 09:22:23 -0700
committerGuido van Rossum <guido@dropbox.com>2016-08-18 09:22:23 -0700
commit97c1adf3935234da716d3289b85f72dcd67e90c2 (patch)
tree0af6f9f258cf26ee9e59db463cc89d04c45bc0b8 /Lib/test/test_enumerate.py
parent0a6996d87d19a524c2a11dd315d96d12083c47d4 (diff)
downloadcpython-git-97c1adf3935234da716d3289b85f72dcd67e90c2.tar.gz
Anti-registration of various ABC methods.
- Issue #25958: Support "anti-registration" of special methods from various ABCs, like __hash__, __iter__ or __len__. All these (and several more) can be set to None in an implementation class and the behavior will be as if the method is not defined at all. (Previously, this mechanism existed only for __hash__, to make mutable classes unhashable.) Code contributed by Andrew Barnert and Ivan Levkivskyi.
Diffstat (limited to 'Lib/test/test_enumerate.py')
-rw-r--r--Lib/test/test_enumerate.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py
index 2630cf2d50..e455adee50 100644
--- a/Lib/test/test_enumerate.py
+++ b/Lib/test/test_enumerate.py
@@ -223,7 +223,7 @@ class TestReversed(unittest.TestCase, PickleTest):
def test_objmethods(self):
# Objects must have __len__() and __getitem__() implemented.
class NoLen(object):
- def __getitem__(self): return 1
+ def __getitem__(self, i): return 1
nl = NoLen()
self.assertRaises(TypeError, reversed, nl)
@@ -232,6 +232,13 @@ class TestReversed(unittest.TestCase, PickleTest):
ngi = NoGetItem()
self.assertRaises(TypeError, reversed, ngi)
+ class Blocked(object):
+ def __getitem__(self, i): return 1
+ def __len__(self): return 2
+ __reversed__ = None
+ b = Blocked()
+ self.assertRaises(TypeError, reversed, b)
+
def test_pickle(self):
for data in 'abc', range(5), tuple(enumerate('abc')), range(1,17,5):
self.check_pickle(reversed(data), list(data)[::-1])