-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'CPUDispatcher' object has no attribute '__globals__' with numba.njit decorated function #277
Comments
I was not able to reproduce the problem on latest master with this code: from typing import TypeVar
import numpy as np
import numpy.typing as npt
from numba import njit
from typeguard import typechecked
T = TypeVar("T", bound=np.generic)
@typechecked
@njit
def numba_sum(
array: npt.NDArray[T],
) -> T:
return np.sum(array)
x = np.arange(4)
s = numba_sum.py_func(x) Did I do something wrong, or is this no longer an issue? |
Closing due to a lack of replies. |
Sorry for the late response. I installed your latest tag from typing import TypeVar
import numpy as np
import numpy.typing as npt
from numba import njit
from typeguard import typechecked
T = TypeVar("T", bound=np.generic)
@typechecked
@njit
def numba_sum(
array: npt.NDArray[T],
) -> T:
return np.sum(array)
x = np.arange(4)
s = numba_sum.py_func(x)
s = numba_sum(x) It gives me the following error message:
The problem is not with the |
Not sure what I did before, but I can reproduce this locally now. |
I am currently in the process of heavily refactoring |
Thank you so much for looking into this... Before, you only executed |
That would explain it 😄 |
The underlying problem is that |
Oh and BTW, it didn't work at all on Pythons older than 3.9. |
Describe the bug
I am using the
numba.njit
decorator to decorate a function. When I executepytest
with typeguard, I get an error when this decorated function is called:AttributeError: 'CPUDispatcher' object has no attribute '__globals__'
. When trying to narrow down the error and trying to reproduce with a minimal working example, I found out that the error only occurs when the decorated function is imported absolutely from a module. When the same function is imported with a relative import there is no error.To Reproduce
I have three different files: two source files (one for absolute and one for relative import) and one pytest file:
src/my_module/numba_typeguard.py (absolute import)
tests/numba_typeguard.py (relative import) same function as above but in
tests
directory.tests/test_numba_typeguard.py
The following is the error I get:
Expected behavior
I expect the error not to depend on relative vs absolute import.
Additional context
As I do not know if this is related to typeguard alone or something else and as I am using the hypermodern python template, I raised also an issue there: cjolowicz/cookiecutter-hypermodern-python#1271
I tried to remove the
py.typed
file in the src/my_module directory, but this did not resolve the error.The text was updated successfully, but these errors were encountered: