mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
bpo-35992: Use PySequence_GetItem only if sq_item is not NULL (GH-11857)
Not using `__class_getitem__()` fallback if there is a non-subcriptable metaclass was caused by a certain asymmetry between how `PySequenceMethods` and `PyMappingMethods` are used in `PyObject_GetItem`. This PR removes this asymmetry. No tests failed, so I assume it was not intentional.
This commit is contained in:
parent
1bf8845f74
commit
ac28147e78
3 changed files with 15 additions and 3 deletions
|
@ -248,7 +248,14 @@ class TestClassGetitem(unittest.TestCase):
|
|||
return f'{cls.__name__}[{item.__name__}]'
|
||||
self.assertEqual(Meta[int], 'Meta[int]')
|
||||
|
||||
def test_class_getitem_metaclass_2(self):
|
||||
def test_class_getitem_with_metaclass(self):
|
||||
class Meta(type): pass
|
||||
class C(metaclass=Meta):
|
||||
def __class_getitem__(cls, item):
|
||||
return f'{cls.__name__}[{item.__name__}]'
|
||||
self.assertEqual(C[int], 'C[int]')
|
||||
|
||||
def test_class_getitem_metaclass_first(self):
|
||||
class Meta(type):
|
||||
def __getitem__(cls, item):
|
||||
return 'from metaclass'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue