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: Py30a4: >>> 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) *  |
Date: 2008-05-27 00:38 |
Guido, what do you say? |
|
|
msg67406 - (view) |
Author: Antoine Pitrou (pitrou) *  |
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) *  |
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): ... and 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) *  |
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 |
/agree |
|
|
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 "", line 1 SyntaxError: named arguments must follow bare * |
|
|
msg273477 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
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. |
|
|