@@ -213,11 +213,16 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value:
213
213
214
214
The tuple is passed to the metaclass constructor.
215
215
"""
216
+ is_named_tuple = cdef .info .is_named_tuple
216
217
ir = builder .mapper .type_to_ir [cdef .info ]
217
218
bases = []
218
219
for cls in cdef .info .mro [1 :]:
219
220
if cls .fullname == 'builtins.object' :
220
221
continue
222
+ if is_named_tuple and cls .fullname in ('typing.Sequence' , 'typing.Iterable' ):
223
+ # HAX: Synthesized base classes added by mypy don't exist at runtime, so skip them.
224
+ # This could break if they were added explicitly, though...
225
+ continue
221
226
# Add the current class to the base classes list of concrete subclasses
222
227
if cls in builder .mapper .type_to_ir :
223
228
base_ir = builder .mapper .type_to_ir [cls ]
@@ -237,6 +242,8 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value:
237
242
# In Python 3.9 TypedDict is not a real type.
238
243
name = '_TypedDict'
239
244
base = builder .get_module_attr (module , name , cdef .line )
245
+ elif is_named_tuple and cls .fullname == 'builtins.tuple' :
246
+ base = builder .get_module_attr ('typing' , 'NamedTuple' , cdef .line )
240
247
else :
241
248
base = builder .load_global_str (cls .name , cdef .line )
242
249
bases .append (base )
@@ -455,7 +462,7 @@ def cache_class_attrs(builder: IRBuilder,
455
462
attrs_to_cache : List [Tuple [Lvalue , RType ]],
456
463
cdef : ClassDef ) -> None :
457
464
"""Add class attributes to be cached to the global cache."""
458
- typ = builder .load_native_type_object (cdef .fullname )
465
+ typ = builder .load_native_type_object (cdef .info . fullname )
459
466
for lval , rtype in attrs_to_cache :
460
467
assert isinstance (lval , NameExpr )
461
468
rval = builder .py_get_attr (typ , lval .name , cdef .line )
0 commit comments