summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_genericclass.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-04 22:21:41 (GMT)
committerGitHub <noreply@github.com>2018-01-04 22:21:41 (GMT)
commitce5b0e9db1b9698e6ffc43ae41cf3a22ca5a6ba6 (patch)
treecde80dea939a4594a505c4cabc0e6f8de56d0f6a /Lib/test/test_genericclass.py
parent87be28f4a1c5b76926c71a3d9f92503f9eb82d51 (diff)
downloadcpython-ce5b0e9db1b9698e6ffc43ae41cf3a22ca5a6ba6.zip
cpython-ce5b0e9db1b9698e6ffc43ae41cf3a22ca5a6ba6.tar.gz
cpython-ce5b0e9db1b9698e6ffc43ae41cf3a22ca5a6ba6.tar.bz2
bpo-32226: Make __class_getitem__ an automatic class method. (#5098)
Diffstat (limited to 'Lib/test/test_genericclass.py')
-rw-r--r--Lib/test/test_genericclass.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_genericclass.py b/Lib/test/test_genericclass.py
index 2057fc0..37e755b 100644
--- a/Lib/test/test_genericclass.py
+++ b/Lib/test/test_genericclass.py
@@ -183,12 +183,21 @@ class TestClassGetitem(unittest.TestCase):
self.assertEqual(D[int], 'D[int]')
self.assertEqual(D[D], 'D[D]')
+ def test_class_getitem_classmethod(self):
+ class C:
+ @classmethod
+ def __class_getitem__(cls, item):
+ return f'{cls.__name__}[{item.__name__}]'
+ class D(C): ...
+ self.assertEqual(D[int], 'D[int]')
+ self.assertEqual(D[D], 'D[D]')
+
def test_class_getitem_patched(self):
class C:
def __init_subclass__(cls):
def __class_getitem__(cls, item):
return f'{cls.__name__}[{item.__name__}]'
- cls.__class_getitem__ = __class_getitem__
+ cls.__class_getitem__ = classmethod(__class_getitem__)
class D(C): ...
self.assertEqual(D[int], 'D[int]')
self.assertEqual(D[D], 'D[D]')
@@ -254,7 +263,7 @@ class CAPITest(unittest.TestCase):
def test_c_class(self):
from _testcapi import Generic, GenericAlias
- self.assertIsInstance(Generic.__class_getitem__(Generic, int), GenericAlias)
+ self.assertIsInstance(Generic.__class_getitem__(int), GenericAlias)
IntGeneric = Generic[int]
self.assertIs(type(IntGeneric), GenericAlias)