This very simple snippet fails on python 2 but passes with python 3:
class A:
def __init__(self, value):
self.value = value
def __setitem__(self, key, value):
pass
r = A(1)
r[80:-10] = list(range(10))
On python2, the interpreter make a call to __len__ which does not exist and therefore fails with:
Traceback (most recent call last):
File "prog.py", line 9, in <module>
AttributeError: A instance has no attribute '__len__'
Where is this behaviour documented? It doesn't make sense to force a container to have a size.