[Python-bugs-list] [ python-Bugs-417930 ] += not assigning to same var it reads

noreply@sourceforge.net noreply@sourceforge.net
Sat, 21 Apr 2001 16:25:51 -0700


Bugs item #417930, was updated on 2001-04-21 16:25
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=417930&group_id=5470

Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Edward Loper (edloper)
Assigned to: Nobody/Anonymous (nobody)
Summary: += not assigning to same var it reads

Initial Comment:
My understanding of the augmented assignment 
statements is that they should always assign to the 
variable that they read from.  However, consider the 
following Python session:
  >>> class A: x = 1  
  ...  
  >>> a=A()
  >>> a.x += 1
  >>> a.x, A.x
  (2, 1)

Here, the expression "a.x += 1" read from a class 
variable, and wrote to an instance variable.  A 
similar effect can occur within a member function:
  >>> class A:
  ...     x = 1
  ...     def f(s): s.x += 1
  ... 
  >>> a = A()
  >>> a.f()
  >>> a.x, A.x
  (2, 1)

I have elicited this behavior in Python 2.0 and 2.1 
under Linux (Redhat 6.0), and Python 2.0 on sunos5.


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

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