Eric Snow <[email protected]> added the comment:
Your problem is with UserList. This is from the implementation:
def __getitem__(self, i):
if isinstance(i, slice):
return self.__class__(self.data[i])
else:
return self.data[i]
So each slice is creating a new Tree. Then the __setitem__() of that new Tree
gets triggered for each item, causing the owner to be set to the new Tree. So
that's the cause.
Is there a particular reason you are subclassing UserList? Consider
subclassing list or collections.abc.MutableSequence instead. Or deal with the
slice semantics manually.
Also, perhaps you expected that a slice would produce a view into the sequence?
I know that's how it works in some programming languages (but not Python,
though you could make it do that if you wanted to).
Regardless, as far as I can tell everything is working as designed. I
recommend closing this.
----------
nosy: +eric.snow
resolution: -> not a bug
status: open -> pending
versions: +Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39110>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com