[issue39110] UserList-subclass Tree slicing changes the original list unexpectedly

Mark Dickinson report at bugs.python.org
Sat Dec 21 06:55:33 EST 2019


Mark Dickinson <dickinsm at gmail.com> added the comment:

[ctarn]

> it works as expected with Python 3.6 (the owner of each of them is d), and Python 3.8 and Python 3.7 work differently

The change in behaviour is the result of a bug fix that was applied in 3.7 and upwards: see GH-13169 and #27639.

As Eric says, UserList is behaving as intended here. Your problem stems from a design flaw in your code, namely that Nodes have owners. If a node exists both in a Tree *and* in a slice of that Tree (which slice, since the #27639 fix, is again a Tree), that node can't have both the original Tree *and* the slice as owner. In this case, what's happening is that accessing `d[0:1]` creates a new Tree object, and the __init__ method for that Tree object then reassigns the "owner" of the node in that slice.

> I don’t know what is discussion list

See https://www.python.org/community/lists/, and particularly https://mail.python.org/mailman/listinfo/python-list

Closing again here, but feel free to start a discussion or ask questions on the list above.

----------
nosy: +mark.dickinson
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39110>
_______________________________________


More information about the Python-bugs-list mailing list