Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3607ef4

Browse files
bpo-35742: Fix test_envar_unimportable in test_builtin. (pythonGH-11561)
Handle the case of an empty module name in PYTHONBREAKPOINT. Fixes a regression introduced in bpo-34756.
1 parent b91140f commit 3607ef4

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Lib/test/test_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ def test_envar_good_path_empty_string(self):
16081608
def test_envar_unimportable(self):
16091609
for envar in (
16101610
'.', '..', '.foo', 'foo.', '.int', 'int.',
1611+
'.foo.bar', '..foo.bar', '/./',
16111612
'nosuchbuiltin',
16121613
'nosuchmodule.nosuchcallable',
16131614
):

Python/sysmodule.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
141141
modulepath = PyUnicode_FromString("builtins");
142142
attrname = envar;
143143
}
144-
else {
144+
else if (last_dot != envar) {
145145
/* Split on the last dot; */
146146
modulepath = PyUnicode_FromStringAndSize(envar, last_dot - envar);
147147
attrname = last_dot + 1;
148148
}
149+
else {
150+
goto warn;
151+
}
149152
if (modulepath == NULL) {
150153
PyMem_RawFree(envar);
151154
return NULL;
@@ -155,27 +158,29 @@ sys_breakpointhook(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
155158
Py_DECREF(modulepath);
156159

157160
if (module == NULL) {
158-
goto error;
161+
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
162+
goto warn;
163+
}
164+
PyMem_RawFree(envar);
165+
return NULL;
159166
}
160167

161168
PyObject *hook = PyObject_GetAttrString(module, attrname);
162169
Py_DECREF(module);
163170

164171
if (hook == NULL) {
165-
goto error;
172+
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
173+
goto warn;
174+
}
175+
PyMem_RawFree(envar);
176+
return NULL;
166177
}
167178
PyMem_RawFree(envar);
168179
PyObject *retval = _PyObject_FastCallKeywords(hook, args, nargs, keywords);
169180
Py_DECREF(hook);
170181
return retval;
171182

172-
error:
173-
if (!PyErr_ExceptionMatches(PyExc_ImportError)
174-
&& !PyErr_ExceptionMatches(PyExc_AttributeError))
175-
{
176-
PyMem_RawFree(envar);
177-
return NULL;
178-
}
183+
warn:
179184
/* If any of the imports went wrong, then warn and ignore. */
180185
PyErr_Clear();
181186
int status = PyErr_WarnFormat(

0 commit comments

Comments
 (0)