[Python-bugs-list] [ python-Bugs-514858 ] complex not entirely immutable
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 08 Feb 2002 13:27:05 -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: Closed
>Resolution: Fixed
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 13:27
Message:
Logged In: YES
user_id=6380
Thanks. I've checked this in. I don't understand why at
first I couldn't reproduce it -- I guess my mind-bending
powers are now also affecting computers. :-)
----------------------------------------------------------------------
Comment By: Gregory Smith (gregsmith)
Date: 2002-02-08 12:10
Message:
Logged In: YES
user_id=292741
should this...
--------------------
static PyMemberDef complex_members[] = {
{"real", T_DOUBLE, offsetof(PyComplexObject, cval.real), 0,
"the real part of a complex number"},
{"imag", T_DOUBLE, offsetof(PyComplexObject, cval.imag), 0,
"the imaginary part of a complex number"},
{0},
};
------- be this ----------??
static PyMemberDef complex_members[] = {
{"real", T_DOUBLE, offsetof(PyComplexObject, cval.real),
READONLY,
"the real part of a complex number"},
{"imag", T_DOUBLE, offsetof(PyComplexObject, cval.imag),
READONLY,
"the imaginary part of a complex number"},
{0},
};
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2002-02-08 07:48
Message:
Logged In: NO
Argh! Now I see it too. Can somebody investigate?
--Guido (who keeps getting logged out from SF -- what's up
with that?)
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-02-08 07:45
Message:
Logged In: YES
user_id=6656
FWIW, I see this too:
Python 2.2+ (#1, Jan 30 2002, 15:27:36)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> 1j
1j
>>> _.real += 1
>>> _
(1+1j)
----------------------------------------------------------------------
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