[Python-ideas] Proto-PEP: Preserving the order of **kwargs in a function.

Barry Warsaw barry at python.org
Thu Apr 10 17:05:30 CEST 2014


Nice PEP; I'm sorry we didn't get a chance to discuss it at the language
summit.

On Apr 05, 2014, at 11:43 PM, Eric Snow wrote:

>Alternate Approaches
>====================
>
>Opt-out Decorator
>-----------------
>
>This is identical to the current proposal with the exception that Python
>would also provide a decorator in functools that would cause collected
>keyword arguments to be packed into a normal dict instead of an
>OrderedDict.
>
>Prognosis:
>
>This would only be necessary if performance is determined to be
>significantly different in some uncommon cases or that there are other
>backward-compatibility concerns that cannot be resolved otherwise.
>
>Opt-in Decorator
>----------------
>
>The status quo would be unchanged.  Instead Python would provide a
>decorator in functools that would register or mark the decorated
>function as one that should get ordered keyword arguments.  The
>performance overhead to check the function at call time would be
>marginal.
>
>Prognosis:
>
>The only real down-side is in the case of function wrappers factories
>(e.g.  functools.partial and many decorators) that aim to perfectly
>preserve keyword arguments by using kwargs in the wrapper definition
>and kwargs unpacking in the call to the wrapped function.  Each wrapper
>would have to be updated separately, though having functools.wraps() do
>this automaticallywould help.

Since this is touching a fundamental and common aspect of the language, I
think a lot of analysis has to be done for both performance and semantics if
the feature is opt-out.  People do crazy things and even small performance
hits add up.  The use cases are valid but rare I submit, so I think most
Python code doesn't care.  Thus I'd lean toward an opt-in approach.

Perhaps a transition period makes sense.  Add both opt-in and opt-out
decorators, implement opt-in by default for Python 3.5 with a -X option to
switch it to opt-out.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140410/72ec4fe5/attachment.sig>


More information about the Python-ideas mailing list