mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Add tests for using PEP560 with classes implemented in C. (#4883)
Based on tests from #4878
This commit is contained in:
parent
9c19b02024
commit
45700fb757
2 changed files with 103 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
from test import support
|
||||
|
||||
|
||||
class TestMROEntry(unittest.TestCase):
|
||||
|
@ -248,5 +249,22 @@ class TestClassGetitem(unittest.TestCase):
|
|||
self.assertEqual(C[int], 'from metaclass')
|
||||
|
||||
|
||||
@support.cpython_only
|
||||
class CAPITest(unittest.TestCase):
|
||||
|
||||
def test_c_class(self):
|
||||
from _testcapi import Generic, GenericAlias
|
||||
self.assertIsInstance(Generic.__class_getitem__(Generic, int), GenericAlias)
|
||||
|
||||
IntGeneric = Generic[int]
|
||||
self.assertIs(type(IntGeneric), GenericAlias)
|
||||
self.assertEqual(IntGeneric.__mro_entries__(()), (int,))
|
||||
class C(IntGeneric):
|
||||
pass
|
||||
self.assertEqual(C.__bases__, (int,))
|
||||
self.assertEqual(C.__orig_bases__, (IntGeneric,))
|
||||
self.assertEqual(C.__mro__, (C, int, object))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue