Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_exception_group_types(self):
self.assertTrue(issubclass(BaseExceptionGroup, BaseException))

def test_exception_is_not_generic_type(self):
with self.assertRaises(TypeError):
with self.assertRaisesRegex(TypeError, 'Exception'):
Exception[OSError]

def test_exception_group_is_generic_type(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_unsubscriptable(self):
for t in int, str, float, Sized, Hashable:
tname = t.__name__
with self.subTest(f"Testing {tname}"):
with self.assertRaises(TypeError):
with self.assertRaisesRegex(TypeError, tname):
t[int]

def test_instantiate(self):
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_type_generic(self):
def test_type_subclass_generic(self):
class MyType(type):
pass
with self.assertRaises(TypeError):
with self.assertRaisesRegex(TypeError, 'MyType'):
MyType[int]

def test_pickle(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Include the type's name in the error message for subscripting non-generic
types.
3 changes: 3 additions & 0 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ PyObject_GetItem(PyObject *o, PyObject *key)
Py_DECREF(meth);
return result;
}
PyErr_Format(PyExc_TypeError, "type '%.200s' is not subscriptable",
((PyTypeObject *)o)->tp_name);
return NULL;
}

return type_error("'%.200s' object is not subscriptable", o);
Expand Down