mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
[3.13] gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing (GH-130934) (#130939)
gh-130932: Fix incorrect exception handling in _PyModule_IsPossiblyShadowing (GH-130934)
I chose to not raise an exception here because I think it would be
confusing for module attribute access to start raising something other
than AttributeError if e.g. the cwd goes away
Without the change in moduleobject.c
```
./python.exe -m unittest test.test_import.ImportTests.test_script_shadowing_stdlib_cwd_failure
...
Assertion failed: (PyErr_Occurred()), function _PyObject_SetAttributeErrorContext, file object.c, line 1253.
```
(cherry picked from commit 0a9ae5ed48
)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
parent
0c088e4442
commit
d5eb490846
3 changed files with 26 additions and 1 deletions
|
@ -908,7 +908,9 @@ _PyModule_IsPossiblyShadowing(PyObject *origin)
|
|||
if (sys_path_0[0] == L'\0') {
|
||||
// if sys.path[0] == "", treat it as if it were the current directory
|
||||
if (!_Py_wgetcwd(sys_path_0_buf, MAXPATHLEN)) {
|
||||
return -1;
|
||||
// If we failed to getcwd, don't raise an exception and instead
|
||||
// let the caller proceed assuming no shadowing
|
||||
return 0;
|
||||
}
|
||||
sys_path_0 = sys_path_0_buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue