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.

classification
Title: Add keyword-only parameter support to PyArg_ParseTupleAndKeywords
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: larry Nosy List: Arfrever, benjamin.peterson, eric.snow, gregory.p.smith, larry, pitrou, python-dev
Priority: normal Keywords:

Created on 2012-03-15 21:49 by larry, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
larry.parsekwonly.diff.2.txt larry, 2012-03-15 21:49 review
larry.parsekwonly.diff.3.txt larry, 2012-03-16 06:34 review
larry.parsekwonly.diff.4.txt larry, 2012-03-17 07:59 review
larry.parsekwonly.diff.5.txt larry, 2012-03-17 17:56 review
larry.parsekwonly.diff.7.txt larry, 2012-03-20 01:43 review
Messages (16)
msg155961 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-15 21:49
This has been split off from #14127 at Antoine's request.

The attached patch adds support for keyword-only arguments to the PyArg_ParseTupleAndKeywords() family of functions.  Includes doc and test.

I used '$' to indicate "all parameters after this are keyword-only"; since they must also be optional it must follow a '|'.  (I would have used '*' but we already use that for 'U*' 's* etc.)

The patch already received one review from Greg P. Smith on the previous issue; the patch I'm attaching here is the second revision incorporating his suggestions.
msg155964 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-15 21:54
Why do you force them to be optional?
msg155965 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-15 21:59
It frankly never occurred to me that you'd want mandatory keyword-only arguments.  Implementing them as optional-only was easy; I'm not sure but making them possibly mandatory (or both!) might complicate matters.

Is there a use case for 'em?
msg155966 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-15 22:01
2012/3/15 Larry Hastings <report@bugs.python.org>:
>
> Larry Hastings <larry@hastings.org> added the comment:
>
> It frankly never occurred to me that you'd want mandatory keyword-only arguments.  Implementing them as optional-only was easy; I'm not sure but making them possibly mandatory (or both!) might complicate matters.
>
> Is there a use case for 'em?

No idea, but at some point we might want them and it parallels the
Python interface.
msg155968 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-15 22:03
How about we leave it for now, and if we need it later we can fix the implementation.  Adding that feature won't break existing calls--we'll just permit $ to occur before/without | in the format string.
msg155979 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-16 00:36
BTW, I have the os.utime patch nearly ready for review; it works, it just needs doc and test.  But it's dependent on this patch--and it'd be smoother if #14127 were finished too.  So I'll hold off on posting the new patch until the fates of these two are decided.
msg155987 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-16 01:21
I want #14325 to go in first.
msg155998 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-16 06:34
Attached is r3 of my patch incorporated Benjamin's suggestions.

> I want #14325 to go in first.

Why do you care?  If I get signoff before 14325 does please explain to me why I should wait.  They don't touch the same lines; should be a clean merge no matter who goes first.
msg156060 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-16 17:32
Shouldn't using vgetargs1 with '$' in the format string just be an error? vgetargs1 doesn't know anything about keyword arguments.
msg156145 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-17 07:59
> Shouldn't using vgetargs1 with '$' in the format string just be
> an error? vgetargs1 doesn't know anything about keyword arguments.

Thank you for catching that!  Serves me right for search-and-destroy style development--I'm not that familiar with getargs.c.

Fixed, which is to say I removed that gunk, in attached patch #4 against current trunk.
msg156186 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-17 17:56
Incorporated the latest round of suggestions from Benjamin's most recent--and very thorough!--review.  Thanks, Benjamin!
msg156361 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-19 21:48
Anyone else?  Or can I get the go-ahead?
msg156362 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-19 21:49
Did you not see Georg's comments?
msg156376 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-03-20 01:43
Whoops!  Actually, I did.  But then I promptly forgot about them.  They're now all incorporated; please see attached patch.
msg156377 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-03-20 01:44
Fine with me now.

2012/3/19 Larry Hastings <report@bugs.python.org>:
>
> Larry Hastings <larry@hastings.org> added the comment:
>
> Whoops!  Actually, I did.  But then I promptly forgot about them.  They're now all incorporated; please see attached patch.
>
> ----------
> Added file: http://bugs.python.org/file24955/larry.parsekwonly.diff.7.txt
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue14328>
> _______________________________________
msg156454 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-03-20 20:06
New changeset 052779d34945 by Larry Hastings in branch 'default':
Issue #14328: Add keyword-only parameters to PyArg_ParseTupleAndKeywords.
http://hg.python.org/cpython/rev/052779d34945
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58536
2012-03-20 20:08:02larrysetstatus: open -> closed
keywords: - patch
resolution: fixed
stage: patch review -> resolved
2012-03-20 20:06:29python-devsetnosy: + python-dev
messages: + msg156454
2012-03-20 01:44:37benjamin.petersonsetmessages: + msg156377
2012-03-20 01:43:15larrysetfiles: + larry.parsekwonly.diff.7.txt

messages: + msg156376
2012-03-19 21:49:36benjamin.petersonsetmessages: + msg156362
2012-03-19 21:48:30larrysetmessages: + msg156361
2012-03-17 17:56:57larrysetfiles: + larry.parsekwonly.diff.5.txt

messages: + msg156186
2012-03-17 07:59:47larrysetfiles: + larry.parsekwonly.diff.4.txt

messages: + msg156145
2012-03-16 17:32:25benjamin.petersonsetmessages: + msg156060
2012-03-16 06:34:42larrysetfiles: + larry.parsekwonly.diff.3.txt

messages: + msg155998
2012-03-16 01:21:31benjamin.petersonsetmessages: + msg155987
2012-03-16 01:05:26eric.snowsetnosy: + eric.snow
2012-03-16 00:36:38larrysetmessages: + msg155979
2012-03-15 22:03:59larrysetmessages: + msg155968
2012-03-15 22:02:58Arfreversetnosy: + Arfrever
2012-03-15 22:01:37benjamin.petersonsetmessages: + msg155966
2012-03-15 21:59:02larrysetmessages: + msg155965
2012-03-15 21:54:57benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg155964
2012-03-15 21:49:18larrycreate