gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords#126564
gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords#126564serhiy-storchaka merged 1 commit intopython:mainfrom
Conversation
Remove _PyArg_UnpackKeywordsWithVararg. Add comments for integer arguments of _PyArg_UnpackKeywords.
0d808e4 to
a511bc2
Compare
erlend-aasland
left a comment
There was a problem hiding this comment.
Neat. Consider this style amendment for IMO slightly more readable generated code:
diff
diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py
index 8b7afbcf3e4..8d1714b1ebe 100644
--- a/Tools/clinic/libclinic/parse_args.py
+++ b/Tools/clinic/libclinic/parse_args.py
@@ -695,13 +695,21 @@ def parse_general(self, clang: CLanguage) -> None:
if has_optional_kw:
self.declarations += "\nPy_ssize_t noptargs = %s + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - %d;" % (nargs, self.min_pos + self.min_kw_only)
unpack_args = '_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL'
- parser_code = [libclinic.normalize_snippet(f"""
- {argsname} = _PyArg_UnpackKeywords({unpack_args}, &_parser,
- /*minpos*/ {self.min_pos}, /*maxpos*/ {self.max_pos}, /*minkw*/ {self.min_kw_only}, /*varpos*/ {1 if self.varpos else 0}, argsbuf);
+ snippet = f"""
+ {argsname} = _PyArg_UnpackKeywords(
+ {unpack_args}, &_parser,
+ /*minpos*/ {self.min_pos},
+ /*maxpos*/ {self.max_pos},
+ /*minkw*/ {self.min_kw_only},
+ /*varpos*/ {1 if self.varpos else 0},
+ argsbuf
+ );
if (!{argsname}) {{{{
goto exit;
}}}}
- """, indent=4)]
+ """
+ snippet = libclinic.normalize_snippet(snippet, indent=4)
+ parser_code = [snippet]
if self.requires_defining_class:
self.flags = 'METH_METHOD|' + self.flags
(This is why auto-formatting for clinic output (with indent-like tool) might be not a bad idea.) But if we are going for multi-line code snippet, lets add also spaces to comments: |
We already do auto-formatting of clinic output1; see Footnotes
|
It would be less readable to me. I have vision problems so I get lost in very scattered code.
I initially wrote it as |
…ythonGH-126564) Remove _PyArg_UnpackKeywordsWithVararg. Add comments for integer arguments of _PyArg_UnpackKeywords.
…ythonGH-126564) Remove _PyArg_UnpackKeywordsWithVararg. Add comments for integer arguments of _PyArg_UnpackKeywords.
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
This is a follow up of #122945. It was not included in #122945 to minimize the diff.