Skip to content

Commit 33ac903

Browse files
committed
Selectively install only third-party typing registrations from numba.core.typing
1 parent fbdff35 commit 33ac903

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

numba_cuda/numba/cuda/typing/context.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,34 +482,33 @@ def is_for_this_target(ftcls):
482482

483483
return current_target.inherits_from(ft_target)
484484

485-
def is_external_type(typ):
486-
"""Check if a type is from outside numba.* namespace."""
485+
def is_external(obj):
486+
"""Check if obj is from outside numba.* namespace."""
487487
try:
488-
return not typ.__module__.startswith("numba.")
488+
return not obj.__module__.startswith("numba.")
489489
except AttributeError:
490490
return True
491491

492-
# Skip functions entirely when external_defs_only=True
493-
if not external_defs_only:
494-
for ftcls in loader.new_registrations("functions"):
495-
if not is_for_this_target(ftcls):
496-
continue
497-
self.insert_function(ftcls(self))
492+
for ftcls in loader.new_registrations("functions"):
493+
if not is_for_this_target(ftcls):
494+
continue
495+
# If external_defs_only, install templates only from external modules
496+
if external_defs_only and not is_external(ftcls):
497+
continue
498+
self.insert_function(ftcls(self))
498499
for ftcls in loader.new_registrations("attributes"):
499500
if not is_for_this_target(ftcls):
500501
continue
501502
# If external_defs_only, check if the type being registered is external
502503
if external_defs_only:
503504
key = getattr(ftcls, "key", None)
504-
if key is not None and not is_external_type(key):
505+
if key is not None and not is_external(key):
505506
continue
506507
self.insert_attributes(ftcls(self))
507508
for gv, gty in loader.new_registrations("globals"):
508509
# If external_defs_only, check the global type's module
509510
if external_defs_only:
510-
if hasattr(gty, "__module__") and gty.__module__.startswith(
511-
"numba."
512-
):
511+
if hasattr(gty, "__module__") and is_external(gty):
513512
continue
514513
existing = self._lookup_global(gv)
515514
if existing is None:

numba_cuda/numba/cuda/typing/typeof.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def typeof_impl(val, c):
6464
if cffi_utils.is_ffi_instance(val):
6565
return types.ffi
6666

67-
# Fallback to Numba's typeof_impl for third-party registrations
68-
from numba.core.typing.typeof import typeof_impl as core_typeof_impl
69-
7067
try:
68+
# Fallback to Numba's typeof_impl for third-party registrations
69+
from numba.core.typing.typeof import typeof_impl as core_typeof_impl
70+
7171
tp = core_typeof_impl(val, c)
7272
if tp is not None:
7373
return tp
74-
except (ValueError, TypeError, AttributeError):
74+
except Exception:
7575
pass
7676

7777
return None

0 commit comments

Comments
 (0)