Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This:
- # >>> a[0] += ['hi']
- #
- # Is pretty much the same as this:
- # >>> x = a[0]
- # >>> x += ['hi']
- # >>> a[0] = x
- class Tuple(tuple):
- def __setitem__(self, *args, **kwargs):
- print("TUPLE __setitem__")
- return super().__setitem__(*args, **kwargs)
- class List(list):
- def __iadd__(self, *args, **kwargs):
- print("LIST __iadd__")
- return super().__iadd__(*args, **kwargs)
- # >>> x = List()
- # >>> y = Tuple((x,))
- # >>> y[0] += List([1])
- # LIST __iadd__
- # TUPLE __setitem__
- # Traceback (most recent call last):
- # File "<stdin>", line 1, in <module>
- # File "<stdin>", line 4, in __setitem__
- # AttributeError: 'super' object has no attribute '__setitem__'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement