Skip to content

Commit 46d6c6b

Browse files
committed
Fix Python 3.9
1 parent 11e6c72 commit 46d6c6b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mypyc/irbuild/classdef.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ def populate_non_ext_bases(builder: IRBuilder, cdef: ClassDef) -> Value:
243243
name = '_TypedDict'
244244
base = builder.get_module_attr(module, name, cdef.line)
245245
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)
247252
else:
248253
base = builder.load_global_str(cls.name, cdef.line)
249254
bases.append(base)
@@ -262,6 +267,10 @@ def find_non_ext_metaclass(builder: IRBuilder, cdef: ClassDef, bases: Value) ->
262267
# In Python 3.9, the metaclass for class-based TypedDict is typing._TypedDictMeta.
263268
# We can't easily calculate it generically, so special case it.
264269
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)
265274

266275
declared_metaclass = builder.add(LoadAddress(type_object_op.type,
267276
type_object_op.src, cdef.line))

0 commit comments

Comments
 (0)