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.

Keyword-only arguments and default arguments always do the wrong thing when combined

See original GitHub issue

Reporting 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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Jun 23, 2020

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.

0reactions
eric-wiesercommented, Jun 23, 2020

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.

Read more comments on GitHub >

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

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