[Python-bugs-list] [ python-Bugs-514858 ] complex not entirely immutable

noreply@sourceforge.net noreply@sourceforge.net
Fri, 08 Feb 2002 07:34:51 -0800


Bugs item #514858, was opened at 2002-02-08 07:29
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=514858&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Gregory Smith (gregsmith)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: complex not entirely immutable

Initial Comment:
.real and .imag of complex are writable, and
really shouldn't be. Examples of badness:
------------------------
>>> sys.version
'2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)]'
>>> c=1+1j
>>> d={c:'spam'}
>>> c
(1+1j)
>>> d
{(1+1j): 'spam'}
>>> d[c]
'spam'
>>> c.real=2.2
>>> c
(2.2000000000000002+1j)
>>> d
{(2.2000000000000002+1j): 'spam'}
>>> d[c]
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in ?
    d[c]
KeyError: (2.2+1j)
-------------------------------->>> c=1+1j
>>> c2=c
>>> c3=c
>>> c is c2, c is c3
(1, 1)
>>> c2 += 1
>>> c3.imag += 1
>>> c is c2, c is c3
(0, 1)
>>> c,c2,c3
((1+2j), (2+1j), (1+2j))
---------------------------

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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-02-08 07:34

Message:
Logged In: YES 
user_id=6380

Eh? Have you hacked your complex number implementation?

When I try this, I get

>>> c.real = 2.2
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'complex' object has only read-only attributes
(assign to .real)
>>> 


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

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