This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients mark.dickinson, nanthil, r.david.murray, steven.daprano
Date 2018-05-24.17:42:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1527183727.89.0.682650639539.issue33636@psf.upfronthosting.co.za>
In-reply-to
Content
I wrote up a response before Mark closed the issue, so despite his excellent no discussion suggestion I'm going to post it for the edification of anyone reading the issue later rather than waste the work :)

Nathan: this is *long* established behavior of python.  It is baked in to the language.  Even if we thought it was a good idea to change it, that cannot be done for backward compatibility reasons.

As for why it works the way it does, consider the following (potentially useful!) cases:

  > [1, 2] * 5
  [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
  > [(1, 2)] * 5
  [(1, 20), (1, 20), (1, 20), (1, 20), (1, 20)]

What Python is doing is filling the created list with *copies of the pointers to the listed values*, which is much more sensible than creating, say, multiple copies in memory of the integers 1 and 2.  That is, you are observing a specific, non-intuitive and rarely useful result of a general rule that *is* useful and intuitive.  Also note that *even if* we wanted to try to make exceptions for "mutable" verses "non-mutable" elements when doing this replication, we can't, because there's a difference between 'copy' and 'deepcopy' in Python, and Python refuses to guess.  So, if you want copies of a list, *you* have to make the correct kind of copies for your application.  Python just copies the pointers like it does for every other type of object multiplied into a list.

By the way, when a core dev closes an issue, the convention is that you can present an argument for it being reopened, but you don't reopen it yourself.  (No way for you to know that that is our convention, which is why I'm telling you :)  

But as should be clear by now, this is a closed issue and further discussion here would be counter-productive for all of us.
History
Date User Action Args
2018-05-24 17:42:07r.david.murraysetrecipients: + r.david.murray, mark.dickinson, steven.daprano, nanthil
2018-05-24 17:42:07r.david.murraysetmessageid: <1527183727.89.0.682650639539.issue33636@psf.upfronthosting.co.za>
2018-05-24 17:42:07r.david.murraylinkissue33636 messages
2018-05-24 17:42:07r.david.murraycreate