def test_ambiguous_functions(self): loader = RegistryLoader(builtin_registry) selectors = defaultdict(OverloadSelector) for impl, fn, sig in loader.new_registrations('functions'): os = selectors[fn] os.append(impl, sig) for fn, os in selectors.items(): all_types = set(t for sig, impl in os.versions for t in sig) # ensure there are no ambiguous overloads for sig in product(all_types, all_types): try: os.find(sig) except NotImplementedError: pass # ignore not implemented cast
def refresh(self): registry = dpu_function_registry try: loader = self._registries[registry] except KeyError: loader = RegistryLoader(registry) self._registries[registry] = loader self.install_registry(registry) # Also refresh typing context, since @overload declarations can # affect it. self.typing_context.refresh()
def install_registry(self, registry): """ Install a *registry* (a imputils.Registry instance) of function and attribute implementations. """ try: loader = self._registries[registry] except KeyError: loader = RegistryLoader(registry) self._registries[registry] = loader self.insert_func_defn(loader.new_registrations('functions')) self._insert_getattr_defn(loader.new_registrations('getattrs')) self._insert_setattr_defn(loader.new_registrations('setattrs')) self._insert_cast_defn(loader.new_registrations('casts')) self._insert_get_constant_defn(loader.new_registrations('constants'))
def create_overload_selector(self, kind): os = OverloadSelector() loader = RegistryLoader(builtin_registry) for impl, sig in loader.new_registrations(kind): os.append(impl, sig) return os