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.
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: 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) * (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): ... 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) * (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 | |
/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 "<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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:33 | admin | set | github: 46865 |
| 2016年08月23日 16:18:28 | gvanrossum | set | messages: + msg273477 |
| 2016年08月23日 15:48:11 | vitorg | set | nosy:
+ vitorg messages: + msg273468 |
| 2008年06月04日 17:57:31 | bgolemon | set | messages: + msg67693 |
| 2008年06月03日 22:29:43 | terry.reedy | set | nosy:
+ terry.reedy messages: + msg67676 |
| 2008年05月27日 17:26:08 | bgolemon | set | messages: + msg67415 |
| 2008年05月27日 17:08:55 | gvanrossum | set | status: open -> closed resolution: not a bug messages: + msg67414 |
| 2008年05月27日 08:46:28 | pitrou | set | nosy:
+ pitrou messages: + msg67406 |
| 2008年05月27日 00:38:28 | benjamin.peterson | set | assignee: gvanrossum messages: + msg67403 nosy: + gvanrossum, benjamin.peterson |
| 2008年05月26日 18:01:33 | bgolemon | set | nosy:
+ bgolemon messages: + msg67380 |
| 2008年04月11日 08:42:49 | mark | create | |