Kaydet (Commit) e9e44484 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #28289: ImportError.__init__ now resets not specified attributes.

üst 2e8c939e
...@@ -1112,6 +1112,20 @@ class ImportErrorTests(unittest.TestCase): ...@@ -1112,6 +1112,20 @@ class ImportErrorTests(unittest.TestCase):
with self.assertRaisesRegex(TypeError, msg): with self.assertRaisesRegex(TypeError, msg):
ImportError('test', invalid='keyword', another=True) ImportError('test', invalid='keyword', another=True)
def test_reset_attributes(self):
exc = ImportError('test', name='name', path='path')
self.assertEqual(exc.args, ('test',))
self.assertEqual(exc.msg, 'test')
self.assertEqual(exc.name, 'name')
self.assertEqual(exc.path, 'path')
# Reset not specified attributes
exc.__init__()
self.assertEqual(exc.args, ())
self.assertEqual(exc.msg, None)
self.assertEqual(exc.name, None)
self.assertEqual(exc.path, None)
def test_non_str_argument(self): def test_non_str_argument(self):
# Issue #15778 # Issue #15778
with check_warnings(('', BytesWarning), quiet=True): with check_warnings(('', BytesWarning), quiet=True):
......
...@@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1 ...@@ -10,6 +10,8 @@ What's New in Python 3.7.0 alpha 1
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #28289: ImportError.__init__ now resets not specified attributes.
- Issue #21578: Fixed misleading error message when ImportError called with - Issue #21578: Fixed misleading error message when ImportError called with
invalid keyword args. invalid keyword args.
......
...@@ -631,19 +631,17 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) ...@@ -631,19 +631,17 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
} }
Py_DECREF(empty_tuple); Py_DECREF(empty_tuple);
if (name) { Py_XINCREF(name);
Py_INCREF(name); Py_XSETREF(self->name, name);
Py_XSETREF(self->name, name);
} Py_XINCREF(path);
if (path) { Py_XSETREF(self->path, path);
Py_INCREF(path);
Py_XSETREF(self->path, path);
}
if (PyTuple_GET_SIZE(args) == 1) { if (PyTuple_GET_SIZE(args) == 1) {
msg = PyTuple_GET_ITEM(args, 0); msg = PyTuple_GET_ITEM(args, 0);
Py_INCREF(msg); Py_INCREF(msg);
Py_XSETREF(self->msg, msg);
} }
Py_XSETREF(self->msg, msg);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment