-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Argument Clinic should understand *args and **kwargs parameters #64490
Comments
Argument Clinic currently prevents the "impl" function from ever seeing the "args" tuple or the "kwargs" dict. There should be a way to ask it to pass those values in to the "impl" function. |
So, let's think about this for a minute. What's the API that we *want* here? If your function has the signature I assert that the impl function should get the same "args" (and "kwargs") that a Python function would--that is, post-argument-processing. In the above example "args" should get (4, 5). This might be somewhat painful to do in round 1, where we're still leveraging off PyArg_ParseTuple*. But in the future it'll be cheaper to do it this way. In any case, it's the right API, so that's what we should do. (Adding Nick just to see if he agrees--he had a use case for *args in the builtin module.) |
Yes, I agree we should follow the Python level semantics, and only capture the excess positional arguments. For the record, the four builtins I flagged as needing this in order to add introspection information: __build_class__
min
|
I think at first step we can support var-positional parameter only when there are no other positional parameters, and var-keyword parameter only when there are no other keyword parameters. So print, max and dict.update will be supported, but __build_class__, map and functools.partial are not. |
I'll try to implement the support of var-positional parameters. |
In case it is helpful, here's my list of examples where the AC and existing signature objects are insufficiently expressive: type(obj)
type(name, bases, mapping)
two different signatures depending on type
range(stop)
range(start, stop)
range(start, stop, step)
dict.pop(key[, default])
default of None has different meaning than missing default
which raises KeyError when the key is missing
itertools.permutations(iterable[, r])
where the absence of *r* implies r=len(iterable) bisect.bisect_right(a, x[, lo[, hi]]) -> index min(iterable, *[, default=obj, key=func]) -> value dict() -> new empty dictionary def sumseq(seq, a=0, b=None):
# Pure python code with nullable int
if b is None:
b = len(seq)
return sum(seq[a:b]) |
FYI I started to work on a different Argument Clinic enhancement, issue bpo-29299: "Argument Clinic: Fix signature of optional positional-only arguments". |
Thank you for your examples Raymond, but they don't directly related to this issue, implementing support of var-positional and var-keyword parameters. I believe that it is possible to solve it, and the solution is complex, but is not extremal hard. I'm working on the first part of this. Your examples show other, more hard issue. It looks to me that the only solution of that issue is to add support of multiple signatures for functions. But this can break the API of the inspect module. |
Once this feature will be implemented, print() should be modified to use Argument Clinic: see the issue bpo-29296. |
…o tuple in argument clinic (python#99233) (cherry picked from commit 69f6cc7)
…pythonGH-32092) (cherry picked from commit 0da7283)
#18609 appears to have added
|
(unassigning since it isn't actively being worked on) @isidentical as FYI for the missing documentation. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: