Skip to content
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

Respect PEP 3102 keyword-only arguments in nopython mode #5655

Open
2 tasks done
astrojuanlu opened this issue Apr 30, 2020 · 3 comments
Open
2 tasks done

Respect PEP 3102 keyword-only arguments in nopython mode #5655

astrojuanlu opened this issue Apr 30, 2020 · 3 comments

Comments

@astrojuanlu
Copy link
Contributor

Reporting a bug

Keyword-only arguments work fine in nopython mode:

In [1]: from numba import njit                                                                                                                                                                                                                

In [2]: def f(a, *, b): 
   ...:     return a * b 
   ...:                                                                                                                                                                                                                                       

In [3]: f(1, b=2)                                                                                                                                                                                                                             
Out[3]: 2

In [4]: f(1, 2)                                                                                                                                                                                                                               
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-c9c271413adf> in <module>
----> 1 f(1, 2)

TypeError: f() takes 1 positional argument but 2 were given

In [5]: nf = njit(f)                                                                                                                                                                                                                          

In [6]: nf(1, b=2)                                                                                                                                                                                                                            
Out[6]: 2

However, I expected nf(1, 2) to fail in the same way as f(1, 2), but it doesn't:

In [7]: nf(1, 2)                                                                                                                                                                                                                              
Out[7]: 2

(perhaps related to #2994?)

@esc
Copy link
Member

esc commented Apr 30, 2020

@astrojuanlu I can reproduce with the following snippet:

from numba import njit


@njit
def f(a, *, b):
    return a * b


print(f(1, b=2))
print(f(1, 2))

I am not sure if this should be classified as a bug or as a feature request.

@stuartarchibald
Copy link
Contributor

I think feature request, Numba's only just got out of having to support both Python 2 and 3. IIRC this is a Python 3 only feature and, as signature handling is very hard, it wasn't of a particularly high priority to handle version specific features when supporting both major versions of Python.

@flying-sheep
Copy link

This is a bug. Numba corrupts the function signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants