numba.jit strips away function type annotations, breaking mypy's analysis
See original GitHub issueReporting a bug
- I have tried using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- I have included a self contained code sample to reproduce the problem. i.e. it’s possible to run as ‘python bug.py’.
Context: Python 3.9, macOS Big Sur 11.5, x86_64
numba.jit decorator strips away function’s type annotations. This is problematic when using mypy for static analysis.
Example:
import numba as nb
import numpy as np
@nb.jit(nb.float64(nb.float64, nb.float64), nopython=True, nogil=True, inline="always")
def my_function(a: float, b: float) -> float:
return 0.5 if np.isnan(a) or np.isnan(b) else 1.0
Mypy’s error:
/path/to/bug.py:4: error: Untyped decorator makes function "my_function" untyped
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Just-in-Time compilation — Numba 0.50.1 documentation
Print out a listing of the function source code annotated line-by-line with the corresponding Numba IR, and the inferred types of the various...
Read more >Supported Python features - Numba
Numba supports function calls using positional and named arguments, as well as arguments with default values and *args (note the argument for *args...
Read more >A ~5 minute guide to Numba — Numba 0.50.1 documentation
A ~5 minute guide to Numba¶. Numba is a just-in-time compiler for Python that works best on code that uses NumPy arrays and...
Read more >Notes on Inlining — Numba 0.50.1 documentation
The decorators such as numba.jit() , numba.extending.overload() and register_jitable() support the keyword ... A python function that takes three arguments.
Read more >First Steps with numba — numba 0.15.1 documentation
One way to compile a function is by using the numba.jit decorator with an ... such a signature by letting numba figure out...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@Jasha10 thank you for the comment. I can confirm that I am able to reproduce this. I have labeled it as a feature request for now. Thank you again for the ping.
Regarding my PR, I stopped working on it (and I didn’t had good results anyway). I still have some interest on the topic, but it’s not affecting my daily work now, so I had to shift priorities.