mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-92114: Improve error message for types with __class_getitem__ = None (GH-92115)
This commit is contained in:
parent
ed711290a0
commit
4d10f703d7
3 changed files with 12 additions and 1 deletions
|
@ -220,6 +220,7 @@ class TestClassGetitem(unittest.TestCase):
|
|||
return None
|
||||
with self.assertRaises(TypeError):
|
||||
C_too_few[int]
|
||||
|
||||
class C_too_many:
|
||||
def __class_getitem__(cls, one, two):
|
||||
return None
|
||||
|
@ -232,16 +233,23 @@ class TestClassGetitem(unittest.TestCase):
|
|||
return None
|
||||
with self.assertRaises(TypeError):
|
||||
C()[int]
|
||||
|
||||
class E: ...
|
||||
e = E()
|
||||
e.__class_getitem__ = lambda cls, item: 'This will not work'
|
||||
with self.assertRaises(TypeError):
|
||||
e[int]
|
||||
|
||||
class C_not_callable:
|
||||
__class_getitem__ = "Surprise!"
|
||||
with self.assertRaises(TypeError):
|
||||
C_not_callable[int]
|
||||
|
||||
class C_is_none(tuple):
|
||||
__class_getitem__ = None
|
||||
with self.assertRaisesRegex(TypeError, "C_is_none"):
|
||||
C_is_none[int]
|
||||
|
||||
def test_class_getitem_metaclass(self):
|
||||
class Meta(type):
|
||||
def __class_getitem__(cls, item):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue