Skip to content

Commit 2d40421

Browse files
committed
Avoid compilation error when using ABC
When trying to use the Mapping ABC as the dispatch type for a registered implementation, we previously tried to load the type for the isinstance check as `typing.Mapping` even if it was imported from `collections.abc`, causing a compilation error due to the fact that we hadn't defined CPyModule_typing. To fix that, this loads the type from the globals dict instead for most types, and using the types in builtin_names for builtin types, which won't be present in the globals dict.
1 parent 1515309 commit 2d40421

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mypyc/irbuild/function.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
setup_func_for_recursive_call
5454
)
5555

56+
from mypyc.primitives.registry import builtin_names
57+
5658

5759
# Top-level transform functions
5860

@@ -782,7 +784,11 @@ def check_if_isinstance(builder: IRBuilder, obj: Value, typ: TypeInfo, line: int
782784
class_ir = builder.mapper.type_to_ir[typ]
783785
return builder.builder.isinstance_native(obj, class_ir, line)
784786
else:
785-
class_obj = builder.load_module_attr_by_fullname(typ.fullname, line)
787+
if typ.fullname in builtin_names:
788+
builtin_addr_type, src = builtin_names[typ.fullname]
789+
class_obj = builder.add(LoadAddress(builtin_addr_type, src, line))
790+
else:
791+
class_obj = builder.load_global_str(typ.name, line)
786792
return builder.call_c(slow_isinstance_op, [obj, class_obj], line)
787793

788794

0 commit comments

Comments
 (0)