[issue20135] FAQ need list mutation answers

2014-09-29 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 138f54622841 by R David Murray in branch '3.4':
#20135: FAQ entry for list mutation.  (See also 6375bf34fff6.)
https://hg.python.org/cpython/rev/138f54622841

New changeset 3d924bbfdcbc by R David Murray in branch 'default':
Merge: #20135: FAQ entry for list mutation.  (See also 90b07d422bd9.)
https://hg.python.org/cpython/rev/3d924bbfdcbc

New changeset 2b9db1fce82e by R David Murray in branch '2.7':
#20135: FAQ entry for list mutation.
https://hg.python.org/cpython/rev/2b9db1fce82e

--

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



[issue20135] FAQ need list mutation answers

2014-09-29 Thread R. David Murray

R. David Murray added the comment:

I accidentally committed the patch early to 3.4/3.5.  I've now addressed Ezio's 
review comment per my suggestion on the review, and committed it to 2.7 as well.

Thanks everyone for your contributions.

--
resolution:  - fixed
stage: commit review - resolved
status: open - closed

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



[issue20135] FAQ need list mutation answers

2014-09-27 Thread R. David Murray

R. David Murray added the comment:

Here is my version of Ezio's patch.

--
Added file: http://bugs.python.org/file36748/mutable_faq.patch

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



[issue20135] FAQ need list mutation answers

2014-08-03 Thread Ezio Melotti

Ezio Melotti added the comment:

Here is a new patch that includes an additional paragraph about mutation and 
non-mutation operations.

--
Added file: http://bugs.python.org/file36236/issue20135-2.diff

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



[issue20135] FAQ need list mutation answers

2014-08-03 Thread Francis MB

Francis MB added the comment:

A) On the example:

+Also note that some operations (e.g. ``y.append(10)``/``y += [10]`` or
+``y.sort()``) mutate

are you saying:
1) y.append(10) divided by y += [10] or
2) y.append(10) and y += [10]

I don't want to split hairs but reading it fast confused me a bit


B) The paragraph:

+  etc.), we can use some specific operations to mutate it and all the variables
+  that refer to it will see
+  the change;

Couldn't be (one newline less):

+  etc.), we can use some specific operations to mutate it and all the variables
+  that refer to it will see the change;

--
nosy: +francismb

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



[issue20135] FAQ need list mutation answers

2014-07-11 Thread R. David Murray

R. David Murray added the comment:

I think the example would be clarified by speaking about mutation operations 
versus non-mutation operations.  After all:

 x = [1]
 y = x
 x = x + [2]
 x
[1, 2]
 y
[1]

At that point including a list += operation would also be beneficial.

--

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



[issue20135] FAQ need list mutation answers

2014-07-11 Thread Ezio Melotti

Ezio Melotti added the comment:

Good point, I'll try to add that to the FAQ.

--

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



[issue20135] FAQ need list mutation answers

2014-07-07 Thread Berker Peksag

Berker Peksag added the comment:

LGTM.

--
nosy: +berker.peksag
stage: needs patch - patch review

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



[issue20135] FAQ need list mutation answers

2014-07-07 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
assignee: docs@python - ezio.melotti
nosy: +rhettinger
stage: patch review - commit review

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



[issue20135] FAQ need list mutation answers

2014-07-06 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3881c12fa3ae by Ezio Melotti in branch '2.7':
#20135: move FAQ about mutable default arguments to the programming FAQs page.
http://hg.python.org/cpython/rev/3881c12fa3ae

New changeset 3b7b0f5aac1e by Ezio Melotti in branch '3.4':
#20135: move FAQ about mutable default arguments to the programming FAQs page.
http://hg.python.org/cpython/rev/3b7b0f5aac1e

New changeset f2a36b01ac02 by Ezio Melotti in branch 'default':
#20135: merge with 3.4.
http://hg.python.org/cpython/rev/f2a36b01ac02

--
nosy: +python-dev

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



[issue20135] FAQ need list mutation answers

2014-07-06 Thread Ezio Melotti

Ezio Melotti added the comment:

I moved the FAQ about mutable default arguments to the programming FAQs page.  
I was going to do a review about new FAQ, but it since I had several comments I 
just tried to rewrite it and make a new patch.
Do you think this is clear enough?

--
Added file: http://bugs.python.org/file35875/issue20135.diff

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



[issue20135] FAQ need list mutation answers

2014-07-06 Thread Mark Lawrence

Mark Lawrence added the comment:

+1 from me, I thought it was crystal clear.

--
nosy: +BreamoreBoy
versions: +Python 3.5 -Python 3.3

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



[issue20135] FAQ need list mutation answers

2014-03-24 Thread M. Volz

M. Volz added the comment:

Thanks David,

I've updated the patch to move the default values question into the programming 
FAQ where you recommended it go, and also changed the title of the mutable list 
question.

--
Added file: http://bugs.python.org/file34604/sortFAQ_defaultval.patch

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



[issue20135] FAQ need list mutation answers

2014-03-12 Thread Éric Araujo

Éric Araujo added the comment:

I agree; if someone goes to the docs, “Programming FAQ” looks more enticing 
than “Design and History”.

--

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



[issue20135] FAQ need list mutation answers

2014-03-12 Thread R. David Murray

R. David Murray added the comment:

M. Votz:  I like your entry, but I think it should be titled Why did changing 
list 'a' also change list 'b'?  That's the form I've always encountered this 
question in.  Then the answer can start of with It didn't, 'a' and 'b' are the 
same list. and then go on with your text.

Since Éric concurs, lets go ahead and move that other answer.  Probably to 
right before How can I pass optional or keywords parameters from one function 
to another?

--

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



[issue20135] FAQ need list mutation answers

2014-03-10 Thread M. Volz

M. Volz added the comment:

I've written and attached a patch for the list mutation question. I took a 
little bit of a different tack on this and addressed a more general question 
whilst still including list mutation as an example. I know the language can get 
a little fussy on these sorts of things- let me know if there's anything that 
could be better worded. 

As for the second issue, as Ezio mentioned there's already an FAQ question 
regarding that- would there be any objection to just copying it into the 
programming section? Or should it be left where it is?

--
Added file: http://bugs.python.org/file34336/defaultdoc_listmut.patch

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



[issue20135] FAQ need list mutation answers

2014-03-10 Thread Éric Araujo

Éric Araujo added the comment:

Resources: http://nedbatchelder.com/text/names.html
   http://python.net/~mwh/hacks/objectthink.html

--
nosy: +eric.araujo

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



[issue20135] FAQ need list mutation answers

2014-03-10 Thread R. David Murray

R. David Murray added the comment:

I'm in favor of moving the FAQ answer Ezio identified to the Programming 
section, myself, but I'd like concurrence from at least one other committer 
before we do it.

--

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



[issue20135] FAQ need list mutation answers

2014-03-09 Thread M. Volz

Changes by M. Volz marie...@gmail.com:


--
nosy: +mvolz

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



[issue20135] FAQ need list mutation answers

2014-01-17 Thread Ezio Melotti

Ezio Melotti added the comment:

http://docs.python.org/3/faq/design.html#why-are-default-values-shared-between-objects

--
nosy: +ezio.melotti

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



[issue20135] FAQ need list mutation answers

2014-01-17 Thread R. David Murray

R. David Murray added the comment:

I *thought* there was a FAQ entry for that.  Didn't think to look for it in the 
design section though :(.  Nor is the title likely to catch the eye of someone 
wondering why their default argument modifications are being unexpectedly 
persistent.  Also, the fact that it starts out with the sentence This type of 
bug commonly bites neophyte programmers is, IMO, a clue it should be in the 
programming section.

--

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



[issue20135] FAQ need list mutation answers

2014-01-16 Thread Fran Bull

Fran Bull added the comment:

I read the FAQ last night and I couldn't see these answered there either. I 
would like to try submitting a patch for this one, probably this evening. It 
will likely be two FAQs in the programming section that go something like:

Why does changing one list change another different list?
This happens:
 a = [1, 2, 3]
 b = a
 b.append(4)
 print a
[1, 2, 3, 4]

because variables are just names for things, in this case 'a' is the list we 
first defined and then b = a says that 'b' is also a name for that list. They 
are both the same list.

Why are my default args wrong?
This happens:

 from datetime import datetime
 class A(object):
...   def __init__(self, created_time=datetime.now()):
... self.created_time = created_time
... 
 an_a = A()
 another_a = A()
 an_a.created_time
datetime.datetime(2014, 1, 16, 10, 40, 54, 33283)
 another_a.created_time
datetime.datetime(2014, 1, 16, 10, 40, 54, 33283)

because default arguments are evaluated when they're read for the first time by 
the interpreter. Usually when the class is imported. A good way to get the 
above to do what you want is to use a default argument of None and check for 
it, like:
 class B(object):
...   def __init__(self, created_time=None):
... if created_time is None:
...   created_time=datetime.now()
... self.created_time = created_time
... 
 a_b = B()
 another_b = B()
 a_b.created_time
datetime.datetime(2014, 1, 16, 10, 44, 44, 956710)
 another_b.created_time
datetime.datetime(2014, 1, 16, 10, 44, 51, 71311)

Feedback appreciated, particularly I'm not sure if this:
'default arguments are evaluated when they're read for the first time by the 
interpreter'
is exactly the right language. I guess I'll look it up.

--
nosy: +Fran.Bull

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



[issue20135] FAQ need list mutation answers

2014-01-16 Thread R. David Murray

R. David Murray added the comment:

Thanks for working on this.

Technically, defaults are evaluated when the 'def' statement is executed, which 
is normally, but not always, at the time that the module is first imported 
(counterexample: nested function definitions).

The answer should also explicitly cover the more common mistake made with 
default keyword values of passing a mutable object and having it get 
persistently modified,and the question phrasing should reflect that.  The 
datetime example is a great first example before getting to the more common 
one, though.

--

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



[issue20135] FAQ need list mutation answers

2014-01-16 Thread Fran Bull

Fran Bull added the comment:

Perhaps a 3rd FAQ something like this?:

Why is changing a list in one instance of a class also changing it in another 
instance of the same class?
This happens:
 class A(object):
...   def __init__(self, fruit=[]):
... self.fruit = fruit
... 
 an_A = A()
 an_A.fruit.append('apple')
 another_A = A()
 print another_A.fruit
['apple']
 another_A.fruit.append('banana')
 print another_A.fruit
['apple', 'banana']
 print an_A.fruit
['apple', 'banana']
 print an_A.fruit is another_A.fruit
True
 print an_A.fruit is A().fruit
True

because of a combination of the above two FAQs, first the default argument is 
evaluated when the 'def' statement is executed and creates an instance of list. 
After that new instances of A have a variable 'fruit' that is the name for that 
instance of list.

I'm not sure whether I should be using as general terms as possible for the Q, 
i.e. 'mutable object' instead of 'list'. I'll reread 
http://docs.python.org/devguide/documenting.html and the FAQs before writing 
the patch.

--

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



[issue20135] FAQ need list mutation answers

2014-01-16 Thread Fran Bull

Changes by Fran Bull fran.b...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file33502/20135.patch

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



[issue20135] FAQ need list mutation answers

2014-01-10 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
stage:  - needs patch
title: mutate list - FAQ need list mutation answers

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