[issue16701] Docs missing the behavior of += (in-place add) for lists.

2012-12-16 Thread Ashwini Chaudhary
New submission from Ashwini Chaudhary: I think the python docs are missing the behavior of += for lists. It actually calls list.extend() but can't find that anywhere in docs expect in source code, http://hg.python.org/cpython/file/2d2d4807a3ed/Objects/listobject.c#l892. -- assignee: do

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2012-12-16 Thread R. David Murray
R. David Murray added the comment: Well, it is effectively documented by the text here: http://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements since "a + b" is logically equivalent to a.extend(b) when a is being updated "in-place". The fact that it is in fact

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-02 Thread Ezio Melotti
Changes by Ezio Melotti : -- nosy: +ezio.melotti stage: -> needs patch ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread benrg
benrg added the comment: This is bizarre: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = y = [1, 2] >>> x += [3] >>> y [1, 2, 3] >>> x = y = {1, 2} >>> x -= {2} >>> y {

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread Ezio Melotti
Ezio Melotti added the comment: > What is "when possible" supposed to mean here? Generally it means "when the object is mutable": >>> l = [1,2,3] >>> id(l) 3074713484 >>> l += [4] >>> id(l) 3074713484 >>> t = (1,2,3) >>> id(t) 3074704004 >>> t += (4,) >>> id(t) 3075304860 Tuples are not mutable

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread R. David Murray
R. David Murray added the comment: If you really want to freak out, try this: >>> x = ([],) >>> x[0] += [1] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> x ([1],) but to answer your question, it has *always* worked that

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread Ezio Melotti
Ezio Melotti added the comment: To clarify, with "depends on the implementation" I meant the way a particular class is implemented (i.e. a class might decide to return a new object even if it's mutable). The behavior of built-in types is well defined and should be the same across all the Pytho

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread benrg
benrg added the comment: > As far as I know Ezio is correct, "when possible" means "when the target is > mutable". The documentation should probably be clarified on that point. Yes, it needs to be made very, very clear in the documentation. As I said, I'm not aware of any other language in wh

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-23 Thread Ezio Melotti
Ezio Melotti added the comment: > Python is designed to be unsurprising; constructs generally mean > what it looks like they mean. AFAIK in C "x += 1" is equivalent to "x++", and both are semantically more about incrementing (mutating) the value of x than about creating a new value that gets a

[issue16701] Docs missing the behavior of += (in-place add) for lists.

2013-01-24 Thread benrg
benrg added the comment: > AFAIK in C "x += 1" is equivalent to "x++", and both are semantically > more about incrementing (mutating) the value of x than about creating a > new value that gets assigned to x. Likewise it seems to me more natural > to interpret "x += y" as "add the value of y to th