Skip to content
Prev Previous commit
Next Next commit
Review (part 1)
  • Loading branch information
AA-Turner committed Sep 18, 2025
commit 8939a899eea46ee0fe20c6d2a2859e18e2af51a3
59 changes: 42 additions & 17 deletions Modules/clinic/_testclinic_kwds.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tools/clinic/libclinic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"argsbuf",
"fastargs",
"kwargs",
"kwds",
"kwnames",
"nargs",
"noptargs",
Expand Down
8 changes: 7 additions & 1 deletion Tools/clinic/libclinic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,5 +1304,11 @@ def cleanup(self) -> str:
def parse_var_keyword(self) -> str:
param_name = self.parser_name
return f"""
{param_name} = (kwargs != NULL) ? Py_NewRef(kwargs) : PyDict_New();
if (kwargs == NULL) {{{{
{param_name} = PyDict_New();
if ({param_name} == NULL) goto exit;
}}}}
else {{{{
{param_name} = Py_NewRef(kwargs);
}}}}
"""
10 changes: 9 additions & 1 deletion Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def dedent(self, line: str) -> str:
class DSLParser:
function: Function | None
state: StateKeeper
expecting_parameters: bool
keyword_only: bool
positional_only: bool
deprecated_positional: VersionTuple | None
Expand Down Expand Up @@ -285,6 +286,7 @@ def __init__(self, clinic: Clinic) -> None:
def reset(self) -> None:
self.function = None
self.state = self.state_dsl_start
self.expecting_parameters = True
self.keyword_only = False
self.positional_only = False
self.deprecated_positional = None
Expand Down Expand Up @@ -848,6 +850,10 @@ def state_parameter(self, line: str) -> None:
# we indented, must be to new parameter docstring column
return self.next(self.state_parameter_docstring_start, line)

if not self.expecting_parameters:
fail('Encountered parameter line when not expecting '
f'parameters: {line}')

line = line.rstrip()
if line.endswith('\\'):
self.parameter_continuation = line[:-1]
Expand Down Expand Up @@ -1128,8 +1134,10 @@ def bad_node(self, node: ast.AST) -> None:
key = f"{parameter_name}_as_{c_name}" if c_name else parameter_name
self.function.parameters[key] = p

if is_vararg or is_var_keyword:
if is_vararg:
self.keyword_only = True
if is_var_keyword:
self.expecting_parameters = False

@staticmethod
def parse_converter(
Expand Down
Loading