mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
bpo-45664: Fix resolve_bases() and new_class() for GenericAlias instance as a base (GH-29298)
(cherry picked from commit 2b318ce1c9
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
abceb66c7e
commit
cb68c0a3a4
3 changed files with 19 additions and 1 deletions
|
@ -1236,6 +1236,17 @@ class ClassCreationTests(unittest.TestCase):
|
|||
self.assertEqual(D.__orig_bases__, (c,))
|
||||
self.assertEqual(D.__mro__, (D, A, object))
|
||||
|
||||
def test_new_class_with_mro_entry_genericalias(self):
|
||||
L1 = types.new_class('L1', (typing.List[int],), {})
|
||||
self.assertEqual(L1.__bases__, (list, typing.Generic))
|
||||
self.assertEqual(L1.__orig_bases__, (typing.List[int],))
|
||||
self.assertEqual(L1.__mro__, (L1, list, typing.Generic, object))
|
||||
|
||||
L2 = types.new_class('L2', (list[int],), {})
|
||||
self.assertEqual(L2.__bases__, (list,))
|
||||
self.assertEqual(L2.__orig_bases__, (list[int],))
|
||||
self.assertEqual(L2.__mro__, (L2, list, object))
|
||||
|
||||
def test_new_class_with_mro_entry_none(self):
|
||||
class A: pass
|
||||
class B: pass
|
||||
|
@ -1351,6 +1362,11 @@ class ClassCreationTests(unittest.TestCase):
|
|||
for bases in [x, y, z, t]:
|
||||
self.assertIs(types.resolve_bases(bases), bases)
|
||||
|
||||
def test_resolve_bases_with_mro_entry(self):
|
||||
self.assertEqual(types.resolve_bases((typing.List[int],)),
|
||||
(list, typing.Generic))
|
||||
self.assertEqual(types.resolve_bases((list[int],)), (list,))
|
||||
|
||||
def test_metaclass_derivation(self):
|
||||
# issue1294232: correct metaclass calculation
|
||||
new_calls = [] # to check the order of __new__ calls
|
||||
|
|
|
@ -82,7 +82,7 @@ def resolve_bases(bases):
|
|||
updated = False
|
||||
shift = 0
|
||||
for i, base in enumerate(bases):
|
||||
if isinstance(base, type):
|
||||
if isinstance(base, type) and not isinstance(base, GenericAlias):
|
||||
continue
|
||||
if not hasattr(base, "__mro_entries__"):
|
||||
continue
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix :func:`types.resolve_bases` and :func:`types.new_class` for
|
||||
:class:`types.GenericAlias` instance as a base.
|
Loading…
Add table
Add a link
Reference in a new issue