Skip to content

Commit

Permalink
Avoid compilation error when using ABC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pranavrajpal committed Jul 9, 2021
1 parent 1515309 commit 2d40421
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mypyc/irbuild/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
setup_func_for_recursive_call
)

from mypyc.primitives.registry import builtin_names


# Top-level transform functions

Expand Down Expand Up @@ -782,7 +784,11 @@ def check_if_isinstance(builder: IRBuilder, obj: Value, typ: TypeInfo, line: int
class_ir = builder.mapper.type_to_ir[typ]
return builder.builder.isinstance_native(obj, class_ir, line)
else:
class_obj = builder.load_module_attr_by_fullname(typ.fullname, line)
if typ.fullname in builtin_names:
builtin_addr_type, src = builtin_names[typ.fullname]
class_obj = builder.add(LoadAddress(builtin_addr_type, src, line))
else:
class_obj = builder.load_global_str(typ.name, line)
return builder.call_c(slow_isinstance_op, [obj, class_obj], line)


Expand Down

0 comments on commit 2d40421

Please sign in to comment.