[ python-Bugs-1436226 ] fix inplace assignment for immutable sequences

SourceForge.net noreply at sourceforge.net
Wed Feb 22 22:20:02 CET 2006


Bugs item #1436226, was opened at 2006-02-21 22:11
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1436226&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: None
>Group: Python 2.4
Status: Open
Resolution: None
Priority: 6
Submitted By: Georg Brandl (gbrandl)
Assigned to: Martin v. Löwis (loewis)
Summary: fix inplace assignment for immutable sequences

Initial Comment:
Currently:

py> tup = ([], )
py> tup[0] += [1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
py> tup
([1],)

With this patch, no exception will be raised when the
item one wants to assign is already there in the tuple.

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2006-02-22 21:20

Message:
Logged In: YES 
user_id=849994

You're right with the error handling *shame*. I had written
the patch a few months ago and just posted it without
looking at it again.

Well, I don't think I'm able to come up with a new patch
only for a couple of days.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2006-02-22 01:44

Message:
Logged In: YES 
user_id=6380

I see no error handling from the PySequence_GetItem() call;
if this causes an error it should take precedence over the
TypeError we're about to raise (IOW we shouldn't raise the
TypeError).

Also, shouldn't the same fix be made for attribute assignment?

Finally -- doing this in PySequence_SetItem is too broad. 
Code like this passes without error:

t = (1, 2)
t[0] = t[0]

That can't be right!  You need to find a code path that's
only taken for += and friends.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1436226&group_id=5470


More information about the Python-bugs-list mailing list