summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIvan Levkivskyi <levkivskyi@gmail.com>2019-02-17 23:13:46 (GMT)
committerGitHub <noreply@github.com>2019-02-17 23:13:46 (GMT)
commitac28147e78c45a6217d348ce90ca5281d91f676f (patch)
tree891d00108f7066f1174788f72dd1696079950b68 /Lib
parent1bf8845f74013c5f1cc5f49a11e52c652a1fb9dd (diff)
downloadcpython-ac28147e78c45a6217d348ce90ca5281d91f676f.zip
cpython-ac28147e78c45a6217d348ce90ca5281d91f676f.tar.gz
cpython-ac28147e78c45a6217d348ce90ca5281d91f676f.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_genericclass.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_genericclass.py b/Lib/test/test_genericclass.py
index 37e755b..37a87bc 100644
--- a/Lib/test/test_genericclass.py
+++ b/Lib/test/test_genericclass.py
@@ -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'