Skip to content

Commit

Permalink
Update AttributeError message to match current Python errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Nov 7, 2024
1 parent 7d37df9 commit 91d74ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pyomo/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion pyomo/common/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 91d74ee

Please sign in to comment.