From 91d74ee7204c735993be1ab78b6f0062f64c9ff2 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 7 Nov 2024 10:53:29 -0700 Subject: [PATCH] Update AttributeError message to match current Python errors --- pyomo/common/config.py | 4 +++- pyomo/common/tests/test_config.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyomo/common/config.py b/pyomo/common/config.py index fe3bc40aa82..8465c947a31 100644 --- a/pyomo/common/config.py +++ b/pyomo/common/config.py @@ -2714,7 +2714,9 @@ def __getattr__(self, attr): # partially constructed ConfigDict (before the _data attribute # was declared) can lead to infinite recursion. if _attr == "_data" or _attr not in self._data: - raise AttributeError("Unknown attribute '%s'" % attr) + raise AttributeError( + f"'{type(self).__name__}' object has no attribute '{attr}'" + ) return ConfigDict.__getitem__(self, _attr) def __setattr__(self, name, value): diff --git a/pyomo/common/tests/test_config.py b/pyomo/common/tests/test_config.py index 5d887a9d980..4906382ae78 100644 --- a/pyomo/common/tests/test_config.py +++ b/pyomo/common/tests/test_config.py @@ -2736,7 +2736,9 @@ def test_getattr_setattr(self): ): config.baz = 10 - with self.assertRaisesRegex(AttributeError, "Unknown attribute 'baz'"): + with self.assertRaisesRegex( + AttributeError, "'ConfigDict' object has no attribute 'baz'" + ): a = config.baz def test_nonString_keys(self):