[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-06-08 Thread Tal Einat
Tal Einat added the comment: How about allowing '|' to be used again after '$'? Keyword arguments would be optional by default, but if there is a '|' after the '$', then those before it are required. Examples: "O|O$O|O" -- one required keyword arg and one optional one. "O|O$OO" -- both keywo

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > I am missing how my PR changes the current behavior, though? Sorry, I misunderstood your changes to the documentation. Other option is to introduce a special symbol that makes the following parameters required if used after (or instead of) $. Like in "O|

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-15 Thread Michael Sullivan
Michael Sullivan added the comment: A downside of the "allow $ twice" approach is that it means splitting up the positional arguments, and a lot of the processing loop is built around the assumption that the index into the keyword list and the index into the argument tuple coincide (for posi

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-15 Thread Michael Sullivan
Michael Sullivan added the comment: The point about a performance penalty is fair---my PR does add a search for the '@' (which I spelled as '`' in my example above) sigil whenever it encounters a '|'. (Though I'm not sure how big the impact would be? Format strings are small so a quick scan

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I thought about this variant. The problem is that you need to scan the format string to the end to determine whether arguments following $ are optional or not. This adds performance penalty for all existing uses of PyArg_ParseTupleAndKeywords() with $. You

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-12 Thread Michael Sullivan
Change by Michael Sullivan : -- keywords: +patch pull_requests: +11865 stage: -> patch review ___ Python tracker ___ ___ Python-bug

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2019-02-01 Thread Michael Sullivan
Michael Sullivan added the comment: How about adding another sigil that indicates that subsequent keyword-only arguments are required? So then your example becomes (using ` as a totally strawman option): PyArg_ParseTupleAndKeywords(args, kwds, "O|O$O`O", kwlist, &a, &b, &d, &c) It's a l

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2018-07-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Support for keyword-only parameters was added in issue14328. Although the implementation never matched the documentation in the case when '|' is not specified before '$'. -- nosy: +larry ___ Python tracker

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2018-07-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The problem is that PyArg_ParseTupleAndKeywords() supports required keyword-only parameters, but only if all parameters are required. "O|O$O" -- last two are optional. "OO$O" -- all are required. This makes designing a consistent syntax more difficult. '|'

[issue34235] PyArg_ParseTupleAndKeywords: support required keyword arguments

2018-07-26 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : In Python the function can have 4 kinds of parameters: def f(a, b=1, *, c, d=2): 1. a is a required positional-or-keyword parameter. 2. b is an optional positional-or-keyword parameter. 3. c is a required keyword-only parameter. 4. d is an optional ke