cpython: 59268ac85f4e (original) (raw)
Mercurial > cpython
changeset 104105:59268ac85f4e
Issue #21578: Fixed misleading error message when ImportError called with invalid keyword args. [#21578]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Tue, 27 Sep 2016 20:51:27 +0300 |
parents | 6117d0e1a5c9(current diff)95549f4970d0(diff) |
children | 675d3f76444d |
files | Misc/NEWS |
diffstat | 3 files changed, 45 insertions(+), 24 deletions(-)[+] [-] Lib/test/test_exceptions.py 16 Misc/NEWS 3 Objects/exceptions.c 50 |
line wrap: on
line diff
--- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1096,6 +1096,22 @@ class ImportErrorTests(unittest.TestCase self.assertEqual(exc.name, 'somename') self.assertEqual(exc.path, 'somepath')
msg = "'invalid' is an invalid keyword argument for this function"[](#l1.7)
with self.assertRaisesRegex(TypeError, msg):[](#l1.8)
ImportError('test', invalid='keyword')[](#l1.9)
with self.assertRaisesRegex(TypeError, msg):[](#l1.11)
ImportError('test', name='name', invalid='keyword')[](#l1.12)
with self.assertRaisesRegex(TypeError, msg):[](#l1.14)
ImportError('test', path='path', invalid='keyword')[](#l1.15)
with self.assertRaisesRegex(TypeError, msg):[](#l1.17)
ImportError(invalid='keyword')[](#l1.18)
with self.assertRaisesRegex(TypeError, msg):[](#l1.20)
ImportError('test', invalid='keyword', another=True)[](#l1.21)
+ def test_non_str_argument(self): # Issue #15778 with check_warnings(('', BytesWarning), quiet=True):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1 Core and Builtins ----------------- +- Issue #21578: Fixed misleading error message when ImportError called with
--- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -612,36 +612,38 @@ SimpleExtendsException(PyExc_BaseExcepti static int ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) {
- static char *kwlist[] = {"name", "path", 0};
- PyObject *empty_tuple; PyObject *msg = NULL; PyObject *name = NULL; PyObject path = NULL; -/ Macro replacement doesn't allow ## to start the first line of a macro,
- so we move the assignment and NULL check into the if-statement. */ -#define GET_KWD(kwd) { [](#l3.15)
- kwd = PyDict_GetItemString(kwds, #kwd); [](#l3.16)
- if (kwd) { [](#l3.17)
Py_INCREF(kwd); \[](#l3.18)
Py_XSETREF(self->kwd, kwd); \[](#l3.19)
if (PyDict_DelItemString(kwds, #kwd)) \[](#l3.20)
return -1; \[](#l3.21)
- } [](#l3.22)
- empty_tuple = PyTuple_New(0);
- if (!empty_tuple)
return -1;[](#l3.28)
- if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwds, "|$OO:ImportError", kwlist,
&name, &path)) {[](#l3.30)
Py_DECREF(empty_tuple);[](#l3.31)
} -return -1;[](#l3.32)
- if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
return -1;[](#l3.46)
- if (PyTuple_GET_SIZE(args) != 1)
return 0;[](#l3.48)
- if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg))
return -1;[](#l3.50)