[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-06 Thread R. David Murray
R. David Murray added the comment: Looks good to me. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-06 Thread Roundup Robot
Roundup Robot added the comment: New changeset 6c222848badd by Martin Panter in branch '2.7': Issue #23406: Clarify documentation on multiplying a sequence https://hg.python.org/cpython/rev/6c222848badd New changeset 57f8c7ad7782 by Martin Panter in branch '3.4': Issue #23406: Clarify

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-06 Thread Martin Panter
Changes by Martin Panter : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-06 Thread Roundup Robot
Roundup Robot added the comment: New changeset 2640a4630e9e by Martin Panter in branch '3.5': Issue #23406: Remove specific line number from susp-ignored.csv https://hg.python.org/cpython/rev/2640a4630e9e New changeset 48f1e9a47301 by Martin Panter in branch 'default': Issue #23406: Merge 3.5

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-04 Thread Martin Panter
Martin Panter added the comment: I was about to commit this, but I think I was wrong about one of my comments. The list that is multiplied is indeed shallow-copied. E.g. “[x] * 1” copies the list, but the reference to x is the same. I propose to commit the second patch, except to revert one

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-04 Thread R. David Murray
R. David Murray added the comment: What is actually happening is that the *contents* of the list are copied, but the list itself is not. This is a consequence of the definition in terms of +. So, yes, that is a shallow copy, but not quite in the sense that mylist.copy() is a shallow copy,

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-04 Thread R. David Murray
R. David Murray added the comment: Sorry, I meant "references to the content are copied" in my first sentence there. This just goes to show why this is complicated to explain :) -- ___ Python tracker

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-04 Thread R. David Murray
R. David Murray added the comment: Or better, "items in the list *s* are not copied..." -- ___ Python tracker ___

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-04 Thread Martin Panter
Martin Panter added the comment: That works for me. Here is a new patch using David’s new wording. -- Added file: http://bugs.python.org/file40369/issue23406_doc_stdtypes.v3.patch ___ Python tracker

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-03 Thread R. David Murray
R. David Murray added the comment: Looks good to me. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-03 Thread Matheus Vieira Portela
Matheus Vieira Portela added the comment: Applying review comments. Now, there is an internal link to the FAQ entry on multidimensional lists. -- Added file: http://bugs.python.org/file40337/issue23406_doc_stdtypes_and_faq.patch ___ Python tracker

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-02 Thread Matheus Vieira Portela
Matheus Vieira Portela added the comment: I'm attaching a patch to update the stdtypes.rst documentation according to our discussion. I've replaced the table explanation to "equivalent to adding s to itself n times" and added a link to the FAQ entry. I'm not sure, however, where to put the

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-02 Thread Martin Panter
Martin Panter added the comment: Left some review comments. The positioning of the link to the FAQ entry seems sensible to me, just that the markup could be better :) -- nosy: +martin.panter stage: needs patch -> patch review versions: +Python 3.6

[issue23406] interning and list comprehension leads to unexpected behavior

2015-09-01 Thread R. David Murray
R. David Murray added the comment: I agree that the table entry could be made more precise. I would suggest replacing the table entry with "equivalent to adding s to itself n times". This formulation serves to explain *why* the multiply operation works the way it does: >>> a = [1, []] >>>

[issue23406] interning and list comprehension leads to unexpected behavior

2015-08-31 Thread Matheus Vieira Portela
Matheus Vieira Portela added the comment: Does anyone else think the note should be expanded? For me, it seems to be pretty accurate although it may indeed be confusing to beginners. If anything, I can work on rewriting it to be more explanatory. -- nosy: +matheus.v.portela

[issue23406] interning and list comprehension leads to unexpected behavior

2015-08-31 Thread R. David Murray
R. David Murray added the comment: Interesting. I usually start with a project's FAQ because I find they usually give me an overview of the project and an indication of its quality :) The footnote looks very explanatory to me already (complete with examples). The 'confusing to beginners'

[issue23406] interning and list comprehension leads to unexpected behavior

2015-08-31 Thread Steven D'Aprano
Steven D'Aprano added the comment: Which note are you referring to? There are at least two mentioned in this thread, the FAQ and a footnote in the docs for stdtypes. If you're referring to the table of operations just below these:

[issue23406] interning and list comprehension leads to unexpected behavior

2015-08-31 Thread Matheus Vieira Portela
Matheus Vieira Portela added the comment: I was referring to the table of operations. So, what if I replace "n shallow copies of s concatenated" by "repeat s n times and concatenate (to create a multidimensional list, refer to [link to FAQ])"? --

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-14 Thread Berker Peksag
Changes by Berker Peksag berker.pek...@gmail.com: -- keywords: +easy stage: - needs patch type: - enhancement versions: +Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23406 ___

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-07 Thread Abraham Smith
New submission from Abraham Smith: Some students were working on matrix routines for practice. The following code: L = [ [0]*3 ]*3 for i in range(3): ...for j in range(3): ...if i==j: L[i][j]=1 was expected to return [[1,0,0],[0,1,0],[0,0,1]] but it returned

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-07 Thread Abraham Smith
Abraham Smith added the comment: (Obviously, there's a copy/paste mistake in the second case; it should read map(id, M).) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23406 ___

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-07 Thread Georg Brandl
Georg Brandl added the comment: There is no interning going on. Multiplying lists just copies references. This is not so surprising if you consider that the case may be simple for nested lists, but what about ``[a] * 3`` with some arbitrary object a? Copying (or even deep copying) that

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-07 Thread Steven D'Aprano
Steven D'Aprano added the comment: This is already a FAQ: https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list I guess this bites every beginning Python programmer, but it's a natural, and desirable, consequence of Python's object model and the fact that *

[issue23406] interning and list comprehension leads to unexpected behavior

2015-02-07 Thread Abraham Smith
Abraham Smith added the comment: Thanks for the helpful responses and correcting my misunderstanding. Regarding improved documentation, I see now that the table at https://docs.python.org/2/library/stdtypes.html#id2 indeed says shallow copies; however, the footnote seems to bury the lede.