diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-03-07 13:18:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-07 13:18:36 (GMT) |
commit | 3594ebca2cacf5d9b5212d2c487fd017cd00e283 (patch) | |
tree | 3ce56e4a8c8ca51c54078f2b37efa469c34afea4 /Python | |
parent | 8acbb93c0763fa53b5959fe05d86ba275c9e8a5b (diff) | |
download | cpython-3594ebca2cacf5d9b5212d2c487fd017cd00e283.zip cpython-3594ebca2cacf5d9b5212d2c487fd017cd00e283.tar.gz cpython-3594ebca2cacf5d9b5212d2c487fd017cd00e283.tar.bz2 |
[3.10] bpo-46940: Don't override existing AttributeError suggestion information (GH-31710) (GH-31724)
When an exception is created in a nested call to PyObject_GetAttr, any
external calls will override the context information of the
AttributeError that we have already placed in the most internal call.
This will cause the suggestions we create to nor work properly as the
attribute name and object that we will be using are the incorrect ones.
To avoid this, we need to check first if these attributes are already
set and bail out if that's the case..
(cherry picked from commit 3b3be05a164da43f201e35b6dafbc840993a4d18)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index ab10b41..21674e0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -6261,9 +6261,12 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc, PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) { - // We do not care if this fails because we are going to restore the - // NameError anyway. - (void)_PyObject_SetAttrId(value, &PyId_name, obj); + PyNameErrorObject* exc = (PyNameErrorObject*) value; + if (exc->name == NULL) { + // We do not care if this fails because we are going to restore the + // NameError anyway. + (void)_PyObject_SetAttrId(value, &PyId_name, obj); + } } PyErr_Restore(type, value, traceback); } |