[3.6] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (… · python/cpython@fab05de (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Commit fab05de
In rare circumstances PyImport_Import() could return NULL without raising an error. (cherry picked from commit 145541c)
File tree
1 file changed
lines changed
1 file changed
lines changed
Lines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1785,9 +1785,13 @@ PyImport_Import(PyObject *module_name) | ||
1785 | 1785 | Py_DECREF(r); |
1786 | 1786 | |
1787 | 1787 | modules = PyImport_GetModuleDict(); |
1788 | -r = PyDict_GetItem(modules, module_name); | |
1789 | -if (r != NULL) | |
1788 | +r = PyDict_GetItemWithError(modules, module_name); | |
1789 | +if (r != NULL) { | |
1790 | 1790 | Py_INCREF(r); |
1791 | + } | |
1792 | +else if (!PyErr_Occurred()) { | |
1793 | +PyErr_SetObject(PyExc_KeyError, module_name); | |
1794 | + } | |
1791 | 1795 | |
1792 | 1796 | err: |
1793 | 1797 | Py_XDECREF(globals); |