msg276952 - (view) |
Author: Manish Goregaokar (manishearth) |
Date: 2016-09-19 07:41 |
When the second argument of complex() is not a number/string, the type error reports the error but prints the type of the first argument: > complex({1:2},1j) Traceback (most recent call last): File "", line 1, in TypeError: complex() argument must be a string or a number, not 'dict' >complex(1j,{1:2}) Traceback (most recent call last): File "", line 1, in TypeError: complex() argument must be a string or a number, not 'complex' >>> complex(1, {1:2}) Traceback (most recent call last): File "", line 1, in TypeError: complex() argument must be a string or a number, not 'int' |
|
|
msg276954 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-19 08:20 |
Contains changes made to Objects/complexobject.c Changed the error message returned when second argument of complex() is not number/string Originally: >complex(1j,{1:2}) Traceback (most recent call last): File "", line 1, in TypeError: complex() argument must be a string or a number, not 'complex' After patch: >complex(1j,{1:2}) Traceback (most recent call last): File "", line 1, in TypeError: complex() argument must be a string or a number, not 'dict' |
|
|
msg276958 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2016-09-19 08:44 |
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 "", line 1, in 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 "", line 1, in 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. |
|
|
msg276970 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2016-09-19 11:04 |
@manishearth: Nice catch! Thanks for the report. @soummyaah: Thanks for the patch. Please could you sign a contributor agreement[1], so that we can commit the patch? As Berker says, tests would be good to have, too. [1] https://www.python.org/psf/contrib/contrib-form/ |
|
|
msg276972 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2016-09-19 11:48 |
This should be fixed in Python 3.5, too. |
|
|
msg277003 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-20 04:00 |
I've signed the contributor agreement form. I think it said that it'll take a few days to process? I've made the changes requested and am currently working on the tests. Will submit a new patch file containing all required changes soon. |
|
|
msg277013 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2016-09-20 06:22 |
Thank you! I look forward to the new patch. |
|
|
msg277022 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-20 12:03 |
Changed error message to: >>> complex({1:2},1) Traceback (most recent call last): File "", line 1, in TypeError: complex() first arg must be a string or a number, not 'dict' >>> complex(1j, {1: 2}) Traceback (most recent call last): File "", line 1, in TypeError: complex() second arg must be a number, not 'dict' Added tests to check the error raised. |
|
|
msg277023 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-20 12:05 |
Apologies. This is the correct file. |
|
|
msg277025 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-20 12:32 |
Squashed the commits for better readability. Also, change required in Python 3.4 as well |
|
|
msg277026 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2016-09-20 12:37 |
Thanks for the patch. We can't fix this in 3.4 because it's in security-fix-only mode: https://docs.python.org/devguide/index.html#status-of-python-branches |
|
|
msg277108 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2016-09-21 07:55 |
Thanks. I'll apply this shortly (but probably not before the weekend). |
|
|
msg277318 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2016-09-24 14:29 |
New changeset 92f4ce2d5ebb by Mark Dickinson in branch '3.5': Issue #28203: Fix incorrect type in error message from complex(1.0, {2:3}). Patch by Soumya Sharma. https://hg.python.org/cpython/rev/92f4ce2d5ebb New changeset a2d93e6bcbcf by Mark Dickinson in branch '3.6': Issue #28203: Merge from 3.5 https://hg.python.org/cpython/rev/a2d93e6bcbcf New changeset 9790bc211107 by Mark Dickinson in branch 'default': Issue #28203: Merge from 3.6 https://hg.python.org/cpython/rev/9790bc211107 |
|
|
msg277319 - (view) |
Author: Mark Dickinson (mark.dickinson) *  |
Date: 2016-09-24 14:32 |
Fixed; thanks. I made a couple of changes: - Use "argument" rather than "arg", to be consistent with the original code (but admittedly not consistent with the rest of the module, where there doesn't seem to be any consistent choice between "arg" and "argument"). - Reformat C and test code to avoid long lines. - Slight rearrangement of the C code so that all of the "i" handling is in one place. |
|
|
msg277353 - (view) |
Author: Soumya Sharma (soummyaah) * |
Date: 2016-09-25 09:49 |
Thanks for the merge! |
|
|