[ python-Patches-1686487 ] Allow any mapping after ** in calls

"SourceForge.net" <[email protected]>
Newsgroups gmane.comp.python.patches
Message-ID <[email protected]>
Patches item #1686487, was opened at 2007-03-23 03:27
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1686487&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.6
>Status: Closed
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Alexander Belopolsky (belopolsky)
Assigned to: Nobody/Anonymous (nobody)
Summary: Allow any mapping after ** in calls

Initial Comment:
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 **. 

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2007-05-21 20:34

Message:
Logged In: YES 
user_id=849994
Originator: NO

I think it just needs someone to commit it. ;) See revision 55495.

----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-05-20 15:30

Message:
Logged In: YES 
user_id=835142
Originator: YES

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?

----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-04-24 13:19

Message:
Logged In: YES 
user_id=835142
Originator: YES

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.
File Added: star-star-mapping-msg.patch

----------------------------------------------------------------------

Comment By: Ziga Seilnacht (zseil)
Date: 2007-04-24 10:32

Message:
Logged In: YES 
user_id=1326842
Originator: NO

The patch looks good to me.  The only thing that could
be improved is the error message.  It would be nice if
it contained the information about kwdict's type.


----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-04-18 19:53

Message:
Logged In: YES 
user_id=835142
Originator: YES

File Added: star-star-mapping.patch

----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-04-18 19:38

Message:
Logged In: YES 
user_id=835142
Originator: YES

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

----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-04-18 18:34

Message:
Logged In: YES 
user_id=835142
Originator: YES

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.




----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-04-18 16:02

Message:
Logged In: YES 
user_id=835142
Originator: YES

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?


----------------------------------------------------------------------

Comment By: Alexander Belopolsky (belopolsky)
Date: 2007-03-23 19:44

Message:
Logged In: YES 
user_id=835142
Originator: YES

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.
File Added: star-star-mapping-1.patch

----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2007-03-23 18:45

Message:
Logged In: YES 
user_id=849994
Originator: NO

Two flaws:
- what if kwdict is NULL? Shouldn't happen, but the old version raises an
error in this case.
- if PyDict_Update fails, tmpdict is leaked.

Please ask on python-dev whether to include this feature.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1686487&group_id=5470
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.