[Python-Dev] List mutation in list_repr?
Hrvoje Niksic
hrvoje.niksic at avl.com
Tue Dec 6 11:29:07 EST 2016
> and I also don’t see any clue in the source as to when [list mutation]
> would actually happen. Since inside the loop, the list object `v` is
> never accessed other than passing `v->ob_item[i]` to the recursive
> repr call, there shouldn’t be any mutation on the list object itself.
The individual object can have a reference to the list and (in extreme
cases) do with it what it pleases:
class Evil:
def __init__(self, l):
self.l = l
def __repr__(self):
del l[:]
return "evil"
l = []
l.append(Evil(l))
l.append(Evil(l))
print(l)
That is not something normal Python code does, but it shouldn't be
allowed to crash the interpreter, either.
More information about the Python-Dev
mailing list