msg219125 - (view) |
Author: Eric Snow (eric.snow) *  |
Date: 2014-05-26 04:31 |
>>> ImportError(spam='spam') Traceback (most recent call last): File "", line 1, in TypeError: ImportError does not take keyword arguments However, it *does* take keyword arguments: >>> ImportError(name='spam', path='spam') ImportError() |
|
|
msg219148 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2014-05-26 09:33 |
Here's a patch with a simple test case. |
|
|
msg219235 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2014-05-27 19:09 |
Thanks for the review, Eric. Here's a new patch. |
|
|
msg219240 - (view) |
Author: Eric Snow (eric.snow) *  |
Date: 2014-05-27 21:16 |
Looks good to me. Thanks for doing this. If no one objects in the meantime, I'll commit this in a few days. |
|
|
msg221640 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2014-06-26 19:59 |
Eric, do you want me to commit the patch? Should this also be committed to the 3.4 branch? |
|
|
msg221755 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2014-06-27 23:53 |
Here's a new patch which uses assertRaisesRegex instead of assertRaises. |
|
|
msg227735 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-09-27 21:29 |
The standard error message for this case is: xxx() got an unexpected keyword argument 'foo' I have no idea where that gets generated (a grep didn't teach me anything useful), but I think it would make sense to use that form for the message. I think the fix can be applied to 3.4. |
|
|
msg228527 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2014-10-05 02:23 |
Thanks for the review, David. > The standard error message for this case is: > > xxx() got an unexpected keyword argument 'foo' I found two similar messages in the codebase: * In Modules/itertoolsmodule.c: PyErr_SetString(PyExc_TypeError, "zip_longest() got an unexpected keyword argument"); * In Python/ceval.c: PyErr_Format(PyExc_TypeError, "%U() got an unexpected " "keyword argument '%S'", co->co_name, keyword); But, in ImportError case it can take more than one keyword arguments: ImportError(spam="SPAM", eggs=True) What error message should be printed for the above case? |
|
|
msg228540 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-10-05 05:07 |
Just the first unexpected keyword. That's what happens if you pass more than one unexpected keyword to a python function. |
|
|
msg271995 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2016-08-04 18:11 |
Assigning to Berker to apply his own patch since Eric has not gotten around to this. |
|
|
msg271996 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-08-04 18:53 |
Why not use PyArg_ParseTupleAndKeywords()? |
|
|
msg272005 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2016-08-05 02:31 |
I am a little uncomfortable with the empty tuple. It's only used as a placeholder for PyArg_ParseTupleAndKeywords. But this way we can achieve consistent error message. Don't know how to choose. |
|
|
msg277516 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-09-27 14:03 |
Ping. |
|
|
msg277519 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2016-09-27 15:59 |
Serhiy's patch looks good to me. It would be nice to add a test for multiple invalid keyword arguments: with self.assertRaisesRegex(TypeError, msg): ImportError('test', invalid='keyword', another=True) Using empty_tuple seems reasonable to me. Brett and Eric, what do you think? |
|
|
msg277521 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2016-09-27 16:14 |
Left a review, but basically LGTM. |
|
|
msg277531 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2016-09-27 17:52 |
New changeset 9b8f0db1944f by Serhiy Storchaka in branch '3.5': Issue #21578: Fixed misleading error message when ImportError called with https://hg.python.org/cpython/rev/9b8f0db1944f New changeset 95549f4970d0 by Serhiy Storchaka in branch '3.6': Issue #21578: Fixed misleading error message when ImportError called with https://hg.python.org/cpython/rev/95549f4970d0 New changeset 59268ac85f4e by Serhiy Storchaka in branch 'default': Issue #21578: Fixed misleading error message when ImportError called with https://hg.python.org/cpython/rev/59268ac85f4e |
|
|
msg277534 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-09-27 18:03 |
Added a test for multiple invalid keyword arguments, added braces, fixed a leak. But there is other oddity in ImportError constructor (). |
|
|