-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-127610: Added validation for more than one var positional and var keyword parameters in inspect.Signature #127657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e4ae535
8aac6f1
64b53a8
97c086c
a7a190a
0f827ed
539d7bc
fb25db2
942a448
0de21a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2992,6 +2992,14 @@ def test2(pod=42, /): | |
with self.assertRaisesRegex(ValueError, 'follows default argument'): | ||
S((pkd, pk)) | ||
|
||
second_args = args.replace(name="second_args") | ||
with self.assertRaisesRegex(ValueError, 'more than one var-positional parameter'): | ||
S((args, second_args)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add also a test for the case when there are other parameters (keyword-only or var-keyword) between two var-positional parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case we will get error: My test: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, there are two errors: "keyword-only parameter before variadic positional parameter" and "more than one variadic positional parameter". Which of them are preferable to report? I think the latter, therefore we should change the order of checks. And tests are needed to ensure that the correct error message is used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case we all need the variables seen_var_positional and seen_var_keyword, to check that these parameters have not occurred before even if the parameter order is wrong, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, yes, you are right. So you need to simply move the new checks up. I still suggest to use You can unify the code for var-positional and var-keyword if use a set instead of two boolean variables. if kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
if kind in seen_var_parameters:
raise ...
seen_var_parameters.add(kind) |
||
|
||
second_kwargs = kwargs.replace(name="second_kwargs") | ||
with self.assertRaisesRegex(ValueError, 'more than one var-keyword parameter'): | ||
S((kwargs, second_kwargs)) | ||
|
||
def test_signature_object_pickle(self): | ||
def foo(a, b, *, c:1={}, **kw) -> {42:'ham'}: pass | ||
foo_partial = functools.partial(foo, a=1) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added validation for more than one var positional and var keyword parameters in ``inspect.Signature.__init__`` | ||
ApostolFet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.