Skip to content

Commit a86fde5

Browse files
committed
Use '%T'
1 parent faf6e53 commit a86fde5

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,16 +2054,16 @@ def __getattr__(self, name):
20542054
raise AttributeError(name)
20552055
with self.assertRaises(AttributeError) as cm:
20562056
getattr(RaiseWithName(), "missing1")
2057-
self.assertEqual(str(cm.exception),
2058-
"'RaiseWithName' object has no attribute 'missing1'")
2057+
self.assertRegex(str(cm.exception),
2058+
r"'.+\.RaiseWithName' object has no attribute 'missing1'")
20592059

20602060
class BareRaise:
20612061
def __getattr__(self, name):
20622062
raise AttributeError
20632063
with self.assertRaises(AttributeError) as cm:
20642064
getattr(BareRaise(), "missing2")
2065-
self.assertEqual(str(cm.exception),
2066-
"'BareRaise' object has no attribute 'missing2'")
2065+
self.assertRegex(str(cm.exception),
2066+
r"'.+\.BareRaise' object has no attribute 'missing2'")
20672067

20682068
class RaiseCustom:
20692069
def __getattr__(self, name):

Objects/exceptions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,8 +2738,8 @@ AttributeError_str(PyObject *op)
27382738
result = PyUnicode_FromFormat("module has no attribute '%U'", name);
27392739
}
27402740
} else {
2741-
result = PyUnicode_FromFormat("'%.200s' object has no attribute '%U'",
2742-
Py_TYPE(obj)->tp_name, name);
2741+
result = PyUnicode_FromFormat("'%T' object has no attribute '%U'",
2742+
obj, name);
27432743
}
27442744
Py_DECREF(obj);
27452745
Py_DECREF(name);

0 commit comments

Comments
 (0)