[issue28203] complex() gives wrong error when the second argument has an invalid type
Berker Peksag
report at bugs.python.org
Mon Sep 19 04:44:40 EDT 2016
Berker Peksag added the comment:
Please upload your patch from a Mercurial clone:
* https://docs.python.org/devguide/setup.html#checkout
* https://docs.python.org/devguide/patch.html
Currently, if you pass a string as a second argument, you get:
>>> complex(1, "1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: complex() second arg can't be a string
So the exception message should probably be changed to include "second arg" or "second argument":
>>> complex(1j, {1: 2})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: complex() second arg must be a number, not 'dict'
Also, there is already a check for second argument in line 952 so the "must be a string" part is probably not needed. We probably need to check whether these two cases can be combined.
You also need to add some tests to Lib/test/test_complex.py.
----------
nosy: +berker.peksag
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28203>
_______________________________________
More information about the Python-bugs-list
mailing list