[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread Eric Snow


Eric Snow  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread ctarn


ctarn  added the comment:

OK, I mean... when I call `a = list(b)`, list() changes `b` unexpectedly, not 
`a != b` in this case. That is why I replace the left operand with `_`.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread ctarn


ctarn  added the comment:

I printed the value of *.owner before and after `_ = list(d...)`, and marked 
the results in the comments.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread ctarn


ctarn  added the comment:

Hi, thanks. It did call `list()` through `_ = list(d[0:2])`

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Can you give an example? Something simple, showing what you tried, what you 
expected, and what happened instead.

This may help: http://sscce.org/

Your bug.py file doesn't ever use the result of calling list(), so how do you 
know it changes the value of the parameter?

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread ctarn


ctarn  added the comment:

In the code, each item of ls = [[0], [1], [2],...] has an owner pointing to d, 
which is a Tree inheriting from collections.UserList.
When `d[0] = a`, and `a.owner = d`, and `_ = list(d[0:1])` is called, a.owner 
will be changed to d[0:1].

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39110] It seems that list() changes the value of the parameter

2019-12-20 Thread ctarn


Change by ctarn :


--
title: It seems that unittest.TestCase.assertListEqual changes the value of its 
parameters -> It seems that list() changes the value of the parameter
Added file: https://bugs.python.org/file48797/bug.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com