Visitar URL original
gh-91058: Add error suggestions to 'import from' import errors by pablogsal · Pull Request #98305 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add NEWS entry
  • Loading branch information
pablogsal committed Oct 17, 2022
commit bdbb37d25d3b59479be461059f97b6121900aeb1
4 changes: 2 additions & 2 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def test_varargs14_kw(self):
itertools.product, 0, repeat=1, foo=2)

def test_varargs15_kw(self):
msg = r"^ImportError\(\) takes at most 2 keyword arguments \(3 given\)$"
msg = r"^ImportError\(\) takes at most 3 keyword arguments \(4 given\)$"
self.assertRaisesRegex(TypeError, msg,
ImportError, 0, name=1, path=2, foo=3)
ImportError, 0, name=1, path=2, name_from=3, foo=3)

def test_varargs16_kw(self):
msg = r"^min\(\) takes at most 2 keyword arguments \(3 given\)$"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:exc:`ImportError` raised from failed ``from <module> import <name>`` now
include suggestions for the value of ``<name>`` based on the available names
in ``<module>``. Patch by Pablo Galindo
2 changes: 1 addition & 1 deletion Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ ImportError_getstate(PyImportErrorObject *self)
Py_DECREF(dict);
return NULL;
}
if (self->path && PyDict_SetItem(dict, &_Py_ID(name_from), self->name_from) < 0) {
if (self->name_from && PyDict_SetItem(dict, &_Py_ID(name_from), self->name_from) < 0) {
Py_DECREF(dict);
return NULL;
}
Expand Down