Keyword-only arguments and default arguments always do the wrong thing when combined
See original GitHub issueReporting a bug
Default arguments never work with keyword-only arguments:
import numba
@numba.njit
def foo(a, b = 1, *, c = 10):
return a + b + c
foo(1, 2)
# gives: 4
# expected: 13
foo(1)
# gives: TypeError: not enough arguments: expected at least 2, got 1
# expected: 12
@numba.njit
def bar(a, b = 1, *, c):
return a + b + c
bar(1, c=2)
# gives: TypeError: missing argument 'b'
# expected: 4
bar(1, 2)
# gives: 4
# expected: TypeError: missing argument 'c'
@numba.njit
def baz(a, b, *, c = 1):
return a + b + c
baz(1, 1)
# gives: TypeError: not enough arguments: expected 3, got 2
# expected: 3
- I am 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 below a minimal working reproducer (if you are unsure how to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Why can't non-default arguments follow default arguments?
There is no sensible answer to this when it comes to KEYWORD-ONLY arguments - why can't default and non-default keyword-only arguments be mixed?...
Read more >Keyword-only Arguments in Python - Medium
A keyword argument is an argument preceded by an identifier (named arguments). Notice that the value here is passed in a function call...
Read more >Positional-only and keyword-only arguments in Python
Make function args positional or keyword - only.In Python, it's possible to force a function argument to be positional- only or keyword -...
Read more >Python SyntaxError: non-default argument follows default
The Python “SyntaxError: non-default argument follows default argument” error is raised when you specify a default argument before a non-default ...
Read more >What are keyword arguments in Python? - Educative.io
Default arguments are keyword arguments whose values are assigned at the time of function definition. Optional arguments are default arguments that, based on ......
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
I think the immediate task here is to just outright ban situations that produce nonsense, fixes can then be performed in the relative safety of knowing that there’s nothing out there half working.
Agreed, it’s way more important to stop code silently producing wrong results than it is to add support for a wider range of calling conventions - so starting with the extensive rewrite is a bad idea.