numba icon indicating copy to clipboard operation
numba copied to clipboard

TypyingError when combining variadic and optional arguments

Open ricardoV94 opened this issue 3 months ago • 2 comments

import numba

@numba.njit
def foo(x, y, z=1):
    return x + y + z

assert foo(1, 1) == 3

@numba.njit
def bar(*xy, z=1):
    x, y = xy
    return x + y + z

assert bar(1, 1) == 3  # Raises TypingError: failed to unpack int64

At some point in the inference it iterates over the xy tuple, thinking it is iterating over (xy, z) function arguments

ricardoV94 avatar Oct 01 '25 10:10 ricardoV94

I can confirm:

esc@artemis [numba_3.13] (git)-[main] ~/git/numba-issues python numba/10258/10258.py
Traceback (most recent call last):
  File "/Users/esc/git/numba-issues/numba/10258/10258.py", line 14, in <module>
    assert bar(1, 1) == 3  # Raises TypingError: failed to unpack int64
           ~~~^^^^^^
  File "/Users/esc/git/numba/numba/core/dispatcher.py", line 424, in _compile_for_args
    error_rewrite(e, 'typing')
    ~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/esc/git/numba/numba/core/dispatcher.py", line 365, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
failed to unpack int64

File "numba/10258/10258.py", line 11:
def bar(*xy, z=1):
    x, y = xy
    ^

During: typing of exhaust iter at /Users/esc/git/numba-issues/numba/10258/10258.py (11)

File "numba/10258/10258.py", line 11:
def bar(*xy, z=1):
    x, y = xy
    ^

During: Pass nopython_type_inference

esc avatar Oct 07 '25 12:10 esc

Let me take a look at this

kaeun97 avatar Nov 05 '25 09:11 kaeun97