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
Allow any mapping after ** in calls #44767
Comments
Python allows arbitrary sequences after * in calls, but an expression following ** must be a (subclass of) dict. The attached patch makes Python accept arbitrary mappings after **. |
Two flaws:
Please ask on python-dev whether to include this feature. |
I've fixed the flaws in star-star-mapping-1.patch . I will ask on python-dev about the feature. If the proposal is accepted, I will probably refactor the code to avoid using the second goto label. |
I have asked on python-dev almost a month ago, but did not get any response: http://mail.python.org/pipermail/python-dev/2007-March/072321.html I have recently posted another message that got no response as well: http://mail.python.org/pipermail/python-dev/2007-April/072653.html Is it possible that my messages are not being delivered to the list? |
Georg, Thanks for reposting my proposal. Since BDFL is +1 on the idea, I feel motivated to polish the patch. In your early comment you noted that kwdict == NULL check may be superficial. I agree. It does not look like it is possible that ext_do_call is called with CALL_FLAG_KW set and a null pointer at the top of the stack. It looks like this may only happen if the stack is corrupted by a misbehaving c extension. In this case, however, throwing a type error is too gentle. PyErr_BadInternalCall() seems to be more appropriate if anything at all. I propose to eliminate the null check for kwdict alltogether. This would be consistent with the way stararg is handled later in this function. I am going to run the testsuit without the null check and will post a revised patch shortly. |
The proposed patch handles ** arguments similar to the way * arguments are treated. If the expression following ** evaluates to an object that is not a dictionary, the new code attempts to update a new dictionary with that object. This procedure is closely similar to what PySequence_Tuple does with * arguments. (Python API does not provide PyMapping_Dict.) If new dictionary is succesfully created and updated, it replaces the original ** argument. If that attempt fails because kwdict is not a mapping (does not have a 'keys' attribute, a type error is raised explaining that a mapping is expected. All other errors, e.g. MemoryError are percolated up. (I am am removing the previous versions of the patch.) |
File Added: star-star-mapping.patch |
The patch looks good to me. The only thing that could |
zseil: It would be nice if it contained the information about kwdict's type. I agree, the new patch adds type information to both * and ** error messages. |
What else needs to be done for the patch to go in? Guido OKed the feature and zseil gave a favorable code review. Is there any reason not to apply it? |
I think it just needs someone to commit it. ;) See revision 55495. |
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: