Add keyword-only parameter support to PyArg_ParseTupleAndKeywords #58536
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/larryhastings'
closed_at = <Date 2012-03-20.20:08:02.518>
created_at = <Date 2012-03-15.21:49:18.370>
labels = ['interpreter-core', 'type-feature']
title = 'Add keyword-only parameter support to PyArg_ParseTupleAndKeywords'
updated_at = <Date 2012-03-20.20:08:02.517>
user = 'https://github.com/larryhastings'bugs.python.org fields:
activity = <Date 2012-03-20.20:08:02.517>
actor = 'larry'
assignee = 'larry'
closed = True
closed_date = <Date 2012-03-20.20:08:02.518>
closer = 'larry'
components = ['Interpreter Core']
creation = <Date 2012-03-15.21:49:18.370>
creator = 'larry'
dependencies = []
files = ['24878', '24883', '24901', '24912', '24955']
hgrepos = []
issue_num = 14328
keywords = []
message_count = 16.0
messages = ['155961', '155964', '155965', '155966', '155968', '155979', '155987', '155998', '156060', '156145', '156186', '156361', '156362', '156376', '156377', '156454']
nosy_count = 7.0
nosy_names = ['gregory.p.smith', 'pitrou', 'larry', 'benjamin.peterson', 'Arfrever', 'python-dev', 'eric.snow']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue14328'
versions = ['Python 3.3']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Activity
larryhastings commentedon Mar 15, 2012
This has been split off from bpo-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.
benjaminp commentedon Mar 15, 2012
Why do you force them to be optional?
larryhastings commentedon Mar 15, 2012
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?
benjaminp commentedon Mar 15, 2012
2012/3/15 Larry Hastings <report@bugs.python.org>:
No idea, but at some point we might want them and it parallels the
Python interface.
larryhastings commentedon Mar 15, 2012
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.
larryhastings commentedon Mar 16, 2012
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 bpo-14127 were finished too. So I'll hold off on posting the new patch until the fates of these two are decided.
benjaminp commentedon Mar 16, 2012
I want bpo-14325 to go in first.
larryhastings commentedon Mar 16, 2012
Attached is r3 of my patch incorporated Benjamin's suggestions.
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.
benjaminp commentedon Mar 16, 2012
Shouldn't using vgetargs1 with '$' in the format string just be an error? vgetargs1 doesn't know anything about keyword arguments.
larryhastings commentedon Mar 17, 2012
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.
larryhastings commentedon Mar 17, 2012
Incorporated the latest round of suggestions from Benjamin's most recent--and very thorough!--review. Thanks, Benjamin!
larryhastings commentedon Mar 19, 2012
Anyone else? Or can I get the go-ahead?
benjaminp commentedon Mar 19, 2012
Did you not see Georg's comments?
larryhastings commentedon Mar 20, 2012
Whoops! Actually, I did. But then I promptly forgot about them. They're now all incorporated; please see attached patch.
benjaminp commentedon Mar 20, 2012
Fine with me now.
2012/3/19 Larry Hastings <report@bugs.python.org>:
python-dev commentedon Mar 20, 2012
New changeset 052779d34945 by Larry Hastings in branch 'default':
Issue bpo-14328: Add keyword-only parameters to PyArg_ParseTupleAndKeywords.
http://hg.python.org/cpython/rev/052779d34945