gh-127610: Added validation for more than one var-positional and var-keyword parameters in inspect.Signature (GH-127657)

This commit is contained in:
Apostol Fet 2024-12-08 13:05:15 +03:00 committed by GitHub
parent 70154855cf
commit 1503fc8f88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View file

@ -2943,11 +2943,19 @@ class Signature:
params = OrderedDict()
top_kind = _POSITIONAL_ONLY
seen_default = False
seen_var_parameters = set()
for param in parameters:
kind = param.kind
name = param.name
if kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
if kind in seen_var_parameters:
msg = f'more than one {kind.description} parameter'
raise ValueError(msg)
seen_var_parameters.add(kind)
if kind < top_kind:
msg = (
'wrong parameter order: {} parameter before {} '