diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-03-07 13:18:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-07 13:18:36 +0000 |
commit | 3594ebca2cacf5d9b5212d2c487fd017cd00e283 (patch) | |
tree | 3ce56e4a8c8ca51c54078f2b37efa469c34afea4 /Lib/test/test_exceptions.py | |
parent | 8acbb93c0763fa53b5959fe05d86ba275c9e8a5b (diff) | |
download | cpython-git-3594ebca2cacf5d9b5212d2c487fd017cd00e283.tar.gz |
[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 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 49739723ee..2bdd7214b0 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -2201,6 +2201,24 @@ class AttributeErrorTests(unittest.TestCase): self.assertNotIn("?", err.getvalue()) + def test_attribute_error_inside_nested_getattr(self): + class A: + bluch = 1 + + class B: + def __getattribute__(self, attr): + a = A() + return a.blich + + try: + B().something + except AttributeError as exc: + with support.captured_stderr() as err: + sys.__excepthook__(*sys.exc_info()) + + self.assertIn("Did you mean", err.getvalue()) + self.assertIn("bluch", err.getvalue()) + class ImportErrorTests(unittest.TestCase): |