complex() raises ValueError when parsing a string argument containing both real and imaginary where one of the real or imaginary is a decimal.
To reproduce:
>>> complex("1.1 + 2.1j")
ValueError: complex() arg is a malformed string
>>> complex("2.1j")
2.1j
>>> complex("1.1 + 2j")
ValueError: complex() arg is a malformed string
>>> complex("1 + 2.1j")
ValueError: complex() arg is a malformed string
Expected results:
>>> complex("1.1 + 2.1j")
(1.1 + 2.1j)
>>> complex("2.1j")
2.1j
>>> complex("1.1 + 2j")
(1.1 + 2j)
>>> complex("1 + 2.1j")
(1 + 2.1j)
This affects all versions up to Python 3.1.2. I haven't tested any of the development builds.
Tests were conducted on a Windows XP 32 bit machine. |