Skip to content

Commit bad7a35

Browse files
authored
gh-110907: AC: Disallow using * with vararg (#110908)
1 parent 14d2d15 commit bad7a35

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

Lib/test/test_clinic.py

+14
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,20 @@ def __init__(self):
359359
"""
360360
self.expect_failure(block, err, lineno=8)
361361

362+
def test_multiple_star_in_args(self):
363+
err = "'my_test_func' uses '*' more than once."
364+
block = """
365+
/*[clinic input]
366+
my_test_func
367+
368+
pos_arg: object
369+
*args: object
370+
*
371+
kw_arg: object
372+
[clinic start generated code]*/
373+
"""
374+
self.expect_failure(block, err, lineno=6)
375+
362376
def test_module_already_got_one(self):
363377
err = "Already defined module 'm'!"
364378
block = """

Objects/clinic/typevarobject.c.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/typevarobject.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ typevar.__new__ as typevar_new
327327
328328
name: object(subclass_of="&PyUnicode_Type")
329329
*constraints: object
330-
*
331330
bound: object = None
332331
covariant: bool = False
333332
contravariant: bool = False
@@ -340,7 +339,7 @@ static PyObject *
340339
typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
341340
PyObject *bound, int covariant, int contravariant,
342341
int infer_variance)
343-
/*[clinic end generated code: output=1d200450ee99226d input=2c07ab87c94f462b]*/
342+
/*[clinic end generated code: output=1d200450ee99226d input=41ae33a916bfe76f]*/
344343
{
345344
if (covariant && contravariant) {
346345
PyErr_SetString(PyExc_ValueError,

Tools/clinic/clinic.py

+9
Original file line numberDiff line numberDiff line change
@@ -5944,6 +5944,7 @@ def parse_star(self, function: Function, version: VersionTuple | None) -> None:
59445944
if version is None:
59455945
if self.keyword_only:
59465946
fail(f"Function {function.name!r} uses '*' more than once.")
5947+
self.check_previous_star()
59475948
self.check_remaining_star()
59485949
self.keyword_only = True
59495950
else:
@@ -6353,6 +6354,14 @@ def check_remaining_star(self, lineno: int | None = None) -> None:
63536354
fail(f"Function {self.function.name!r} specifies {symbol!r} "
63546355
f"without following parameters.", line_number=lineno)
63556356

6357+
def check_previous_star(self, lineno: int | None = None) -> None:
6358+
assert isinstance(self.function, Function)
6359+
6360+
for p in self.function.parameters.values():
6361+
if p.kind == inspect.Parameter.VAR_POSITIONAL:
6362+
fail(f"Function {self.function.name!r} uses '*' more than once.")
6363+
6364+
63566365
def do_post_block_processing_cleanup(self, lineno: int) -> None:
63576366
"""
63586367
Called when processing the block is done.

0 commit comments

Comments
 (0)