summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-12-05 21:26:37 (GMT)
committerGitHub <noreply@github.com>2021-12-05 21:26:37 (GMT)
commitcb68c0a3a4aeb4ec58ab1f71b70bc8bfecbceef6 (patch)
tree60b411fd1cf2c5c12ab35d92adf79f62911916c9 /Lib
parentabceb66c7e33d165361d8a26efb3770faa721aff (diff)
downloadcpython-cb68c0a3a4aeb4ec58ab1f71b70bc8bfecbceef6.zip
cpython-cb68c0a3a4aeb4ec58ab1f71b70bc8bfecbceef6.tar.gz
cpython-cb68c0a3a4aeb4ec58ab1f71b70bc8bfecbceef6.tar.bz2
bpo-45664: Fix resolve_bases() and new_class() for GenericAlias instance as a base (GH-29298)
(cherry picked from commit 2b318ce1c988b7b6e3caf293d55f289e066b6e0f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py16
-rw-r--r--Lib/types.py2
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index b1218ab..3dfda5c 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -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
diff --git a/Lib/types.py b/Lib/types.py
index c2dc97d..62122a9 100644
--- a/Lib/types.py
+++ b/Lib/types.py
@@ -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