question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numba.jit strips away function type annotations, breaking mypy's analysis

See original GitHub issue

Reporting 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
esccommented, Dec 6, 2021

@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.

1reaction
castarcocommented, Nov 4, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found