[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-18 Thread Mark Dickinson
Mark Dickinson added the comment: @andy.chugunov: tuples are immutable in the sense that you can't put a new object into a tuple or remove objects from a tuple. That doesn't mean that tuples can't contain mutable objects, or prevent you from mutating the objects inside a tuple. So the append

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-18 Thread Mark Dickinson
Mark Dickinson added the comment: Another 'fix' would be to allow assignment to a tuple item in the case that the item being assigned is the same (in the sense of 'is') as the item already in the tuple. Then the '+=' operation would succeed, but the tuple would remain immutable. -- n

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-17 Thread Andy Chugunov
Andy Chugunov added the comment: Thank you for the clarification! The exception is appropriate as tuples have to stay immutable. Got it. Could you please also explain a bit about the append() call? Should it in theory raise an exception as well or is such clean behavior intended? --

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-17 Thread Ronald Oussoren
Ronald Oussoren added the comment: You've got a point there. What about this patch (but then with proper english grammer)? BTW. Actually fixing this wart would be possible, but at a significant cost: you'd have to change the implementation of LHS += RHS from: tmp = LHS tmp = tmp.__iadd_

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-17 Thread R. David Murray
R. David Murray added the comment: This gets reported periodically. I wonder if it is time for a FAQ entry. There doesn't seem to be one yet. -- nosy: +r.david.murray ___ Python tracker _

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-14 Thread Florent Xicluna
Changes by Florent Xicluna : -- nosy: +flox ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-14 Thread Ronald Oussoren
Ronald Oussoren added the comment: I'm closing this issue as rejected because the current behavior is intentional, although it is confusing (IMO). -- resolution: -> rejected status: open -> closed ___ Python tracker

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-14 Thread Ronald Oussoren
Ronald Oussoren added the comment: This is a side effect to the way the in place operators work. Basically "a[0] += [3]" is evaluated as: a[0] = a[0].__iadd__([3]) The call to __iadd__ succeeds, which is why the list is updated, but you get an exception when the interpreter tries to updat

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-14 Thread Ronald Oussoren
Changes by Ronald Oussoren : -- assignee: -> ronaldoussoren ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: ht

[issue17973] '+=' on a list inside tuple both succeeds and raises an exception

2013-05-14 Thread Andy Chugunov
New submission from Andy Chugunov: At the same time append() succeeds silently, while simple '+' fails. Here's an example: >>> a = ([1],) >>> a[0].append(2) >>> a ([1, 2],) >>> a[0] += [3] Traceback (most recent call last): File "", line 1, in a[0] += [3] TypeError: 'tuple' object does no