Skip to content

Commit 9e02b3f

Browse files
committed
Add Parameter.is_variable_length()
1 parent b6785c4 commit 9e02b3f

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

Tools/clinic/libclinic/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def _render_non_self(
274274
data.modifications.append('/* modifications for ' + name + ' */\n' + modifications.rstrip())
275275

276276
# keywords
277-
if parameter.is_vararg() or parameter.is_var_keyword():
277+
if parameter.is_variable_length():
278278
pass
279279
elif parameter.is_positional_only():
280280
data.keywords.append('')

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,7 @@ def add_parameter(text: str) -> None:
14681468
name = p.converter.signature_name or p.name
14691469
p_lines.append(name)
14701470

1471-
if (
1472-
not (p.is_vararg() or p.is_var_keyword())
1473-
and p.converter.is_optional()
1474-
):
1471+
if not p.is_variable_length() and p.converter.is_optional():
14751472
p_lines.append('=')
14761473
value = p.converter.py_default
14771474
if not value:

Tools/clinic/libclinic/function.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,24 @@ class Parameter:
214214
def __repr__(self) -> str:
215215
return f'<clinic.Parameter {self.name!r}>'
216216

217-
def is_keyword_only(self) -> bool:
218-
return self.kind == inspect.Parameter.KEYWORD_ONLY
219-
220217
def is_positional_only(self) -> bool:
221218
return self.kind == inspect.Parameter.POSITIONAL_ONLY
222219

220+
def is_positional_or_keyword(self) -> bool:
221+
return self.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
222+
223+
def is_keyword_only(self) -> bool:
224+
return self.kind == inspect.Parameter.KEYWORD_ONLY
225+
223226
def is_vararg(self) -> bool:
224227
return self.kind == inspect.Parameter.VAR_POSITIONAL
225228

226229
def is_var_keyword(self) -> bool:
227230
return self.kind == inspect.Parameter.VAR_KEYWORD
228231

232+
def is_variable_length(self) -> bool:
233+
return self.is_vararg() or self.is_var_keyword()
234+
229235
def is_optional(self) -> bool:
230236
return not self.is_vararg() and (self.default is not unspecified)
231237

Tools/clinic/libclinic/parse_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def declare_parser(
3636

3737
num_keywords = len([
3838
p for p in f.parameters.values()
39-
if not p.is_positional_only() and not (p.is_vararg() or p.is_var_keyword())
39+
if p.is_positional_or_keyword() or p.is_keyword_only()
4040
])
4141

4242
condition = '#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)'

0 commit comments

Comments
 (0)