@@ -243,7 +243,12 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value:
243
243
name = '_TypedDict'
244
244
base = builder .get_module_attr (module , name , cdef .line )
245
245
elif is_named_tuple and cls .fullname == 'builtins.tuple' :
246
- base = builder .get_module_attr ('typing' , 'NamedTuple' , cdef .line )
246
+ if builder .options .capi_version < (3 , 9 ):
247
+ name = 'NamedTuple'
248
+ else :
249
+ # This was changed in Python 3.9.
250
+ name = '_NamedTuple'
251
+ base = builder .get_module_attr ('typing' , name , cdef .line )
247
252
else :
248
253
base = builder .load_global_str (cls .name , cdef .line )
249
254
bases .append (base )
@@ -262,6 +267,10 @@ def find_non_ext_metaclass(builder: IRBuilder, cdef: ClassDef, bases: Value) ->
262
267
# In Python 3.9, the metaclass for class-based TypedDict is typing._TypedDictMeta.
263
268
# We can't easily calculate it generically, so special case it.
264
269
return builder .get_module_attr ('typing' , '_TypedDictMeta' , cdef .line )
270
+ elif cdef .info .is_named_tuple and builder .options .capi_version >= (3 , 9 ):
271
+ # In Python 3.9, the metaclass for class-based NamedTuple is typing.NamedTupleMeta.
272
+ # We can't easily calculate it generically, so special case it.
273
+ return builder .get_module_attr ('typing' , 'NamedTupleMeta' , cdef .line )
265
274
266
275
declared_metaclass = builder .add (LoadAddress (type_object_op .type ,
267
276
type_object_op .src , cdef .line ))
0 commit comments