This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: inconsistency with bare * in parameter list
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: benjamin.peterson, bgolemon, gvanrossum, mark, pitrou, terry.reedy, vitorg
Priority: normal Keywords:

Created on 2008-04-11 08:42 by mark, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (10)
msg65340 - (view) Author: Mark Summerfield (mark) * Date: 2008-04-11 08:42
A bare * in a parameter list behaves differently depending on what
follows it:


>>> def f(*, a=1, b=2): return 1

>>> def g(*, **kwargs): return 1
SyntaxError: named arguments must follow bare * (<pyshell#10>, line 1)

I don't know if this is a bug or not but thought it worth querying. This
case does not seem to be mentioned in PEP 3102.
msg67380 - (view) Author: Buck Golemon (bgolemon) Date: 2008-05-26 18:01
It seems like f(a=1, b=2) and g(a=1, b=2) should be equivalent. Anyone
agree, disagree?
msg67403 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-27 00:38
Guido, what do you say?
msg67406 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-05-27 08:46
Agreed with Buck and Mark, this looks like a bug. Or, rather, a
limitation, since a bare * just before a **kwargs should be useless if I
understand correctly.
msg67414 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-05-27 17:08
I see it differently. The rule is simply that if you use a bare * you
*must* follow it with at least one argument (that's not **k).  This
makes sense since otherwise the * is redundant.  Think about it; there
is nothing different between

def g(*, **kwds): ...


def g(**kwds): ...
msg67415 - (view) Author: Buck Golemon (bgolemon) Date: 2008-05-27 17:26
If there's no difference then they should work the same?
I agree there's probably little value in 'fixing' it.
msg67676 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-06-03 22:29
Rationale for banning f(*,**k): it could represent a bug (intended bare
name(s) omitted) that should be flagged, a lack of clear understanding
of the redundancy, or a somewhat unPythonic stylistic preference for
useless redundancy.  I consider the first the most likely in practice,
though I also did not see the redundancy at first.  Guido has used the
'likely a bug' rationale for other design decisions.
msg67693 - (view) Author: Buck Golemon (bgolemon) Date: 2008-06-04 17:57
msg273468 - (view) Author: (vitorg) Date: 2016-08-23 15:48
Here is example where it's necessary, but still raising an error:
>>> def my_method(self, *, **kwargs):
...     pass
  File "<stdin>", line 1
SyntaxError: named arguments must follow bare *
msg273477 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-08-23 16:18
I promise you it's not necessary in that example. Leaving out the '*' has the same effect as what you intend there.
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46865
2016-08-23 16:18:28gvanrossumsetmessages: + msg273477
2016-08-23 15:48:11vitorgsetnosy: + vitorg
messages: + msg273468
2008-06-04 17:57:31bgolemonsetmessages: + msg67693
2008-06-03 22:29:43terry.reedysetnosy: + terry.reedy
messages: + msg67676
2008-05-27 17:26:08bgolemonsetmessages: + msg67415
2008-05-27 17:08:55gvanrossumsetstatus: open -> closed
resolution: not a bug
messages: + msg67414
2008-05-27 08:46:28pitrousetnosy: + pitrou
messages: + msg67406
2008-05-27 00:38:28benjamin.petersonsetassignee: gvanrossum
messages: + msg67403
nosy: + gvanrossum, benjamin.peterson
2008-05-26 18:01:33bgolemonsetnosy: + bgolemon
messages: + msg67380
2008-04-11 08:42:49markcreate