[issue9314] inconsistent result when concatenating list with iterators

2010-07-21 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
status: open -> closed

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-21 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

On Wed, Jul 21, 2010 at 2:09 AM, Ray.Allen  wrote:
..
> Does this means "a += b" is not the same as "a = a + b"?

For immutable a, the two are practically the same, for mutable, they
are necessarily different.   This is explained in __iadd__
documentation:

"""
These methods are called to implement the augmented arithmetic
assignments (+=, -=, *=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=).
These methods should attempt to do the operation in-place (modifying
self) and return the result (which could be, but does not have to be,
self). If a specific method is not defined, the augmented assignment
falls back to the normal methods. For instance, to execute the
statement x += y, where x is an instance of a class that has an
__iadd__() method, x.__iadd__(y) is called. If x is an instance of a
class that does not define a __iadd__() method, x.__add__(y) and
y.__radd__(x) are considered, as with the evaluation of x + y.
"""  http://docs.python.org/reference/datamodel.html?#object.__iadd__

> I'd think this can be seen as a pitfall for python.

No.  Please see PEP 203 for the rationale.
http://www.python.org/dev/peps/pep-0203/

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Ray.Allen

Ray.Allen  added the comment:

Alexander:

> When a is mutable, a += b updates it in-place, so there is no ambiguity: the 
> type of a cannot change.  When you do a + b, there is no reason to treat a as 
> more deserving than b when selecting the type of the result

Does this means "a += b" is not the same as "a = a + b"? I'd think this can be 
seen as a pitfall for python.

--
nosy: +ysj.ray

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Hmm, I'm still not entirely sure that += shouldn't disallow this as well, just 
because of the inconsistency. I understand the reasoning now, but it feels like 
maybe it should be an implementation detail, and it should just be disallowed 
(refuse to guess).

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

> I thought it was common to requalify a bug report into a doc bug.

That's upto you and OP.  My rule of thumb is if the title reads as either code 
or doc bug, it's ok to reclassify.  If not, it is better to open a separate 
issue.

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Éric Araujo

Éric Araujo  added the comment:

Thanks for the explanation of pending, I thought the mysterious Roundup/browser 
bug had changed the status in my back.

Searching for __iadd__ gave me only library/collections; library/stdtypes says 
very little.

I thought it was common to requalify a bug report into a doc bug.

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

> why the pending status?

To me this is a way to say "I will close this next time I look unless someone 
will change my mind."  "pending" has a nice property that it will change to 
"open" once someone adds a comment.  This is exactly what I wanted in this case.

> do you think this is a doc bug?

Interestingly, I could not find any discussion of += for lists in the docs.  
This maybe because "+=" is not really search friendly.  In any case, a doc bug 
(if any) should be reported under a separate issue.

--
status: pending -> open

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Éric Araujo

Changes by Éric Araujo :


--
status: open -> pending

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Éric Araujo

Éric Araujo  added the comment:

Alexander, why the pending status?

Dirkjan, do you think this is a doc bug?

--
status: pending -> open

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
assignee:  -> belopolsky
resolution:  -> rejected
stage:  -> committed/rejected
status: open -> pending

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Hmm, that's pretty subtle. I guess I understand, at least.

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

Note that immutable types are consistent:

>>> x = tuple('abc')
>>> x += 'def'
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate tuple (not "str") to tuple

>>> x + 'def'
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate tuple (not "str") to tuple

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
type:  -> feature request
versions: +Python 3.2 -Python 2.6

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

> I don't understand is why a += b is different from a + b
> in this respect.

When a is mutable, a += b updates it in-place, so there is no ambiguity: the 
type of a cannot change.  When you do a + b, there is no reason to treat a as 
more deserving than b when selecting the type of the result.

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Dirkjan Ochtman

Dirkjan Ochtman  added the comment:

Sure, but:

>>> a = ['a', 'b', 'c']
>>> a += 'def'
>>> a
['a', 'b', 'c', 'd', 'e', 'f']

I think either way is fine (I'm probably on the side of refusing to guess), but 
what I don't understand is why a += b is different from a + b in this respect.

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Alexander Belopolsky

Alexander Belopolsky  added the comment:

> In other words, if iadd can deal with it, why can't add?

Should ['a', 'b', 'c'] + 'def' return ['a, 'b', 'c', 'd' , 'e', 'f'] or 
'abcdef'?

"In the face of ambiguity, refuse the temptation to guess."

--
nosy: +belopolsky

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc  added the comment:

for any *iterable*!

--

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc  added the comment:

This actually works for any iterator:
>>> l = []
>>> l += 'abc'
>>> l
['a', 'b', 'c']

--
nosy: +amaury.forgeotdarc

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Éric Araujo

Changes by Éric Araujo :


--
nosy: +merwok

___
Python tracker 

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



[issue9314] inconsistent result when concatenating list with iterators

2010-07-20 Thread Dirkjan Ochtman

New submission from Dirkjan Ochtman :

This seems wrong:

>>> a = []
>>> b = iter(['c', 'd'])
>>> a += b
>>> c = []
>>> c + iter(['d', 'e'])
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate list (not "listiterator") to list

In other words, if iadd can deal with it, why can't add?

--
components: Interpreter Core
messages: 110887
nosy: djc
priority: normal
severity: normal
status: open
title: inconsistent result when concatenating list with iterators
versions: Python 2.6

___
Python tracker 

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