[Python-ideas] Let's be more orderly!
Terry Jan Reedy
tjreedy at udel.edu
Thu May 23 23:06:09 CEST 2013
On 5/23/2013 12:36 PM, Haoyi Li wrote:
> >The question is, how would you _specify_ that option?
>
> This seems like the perfect use case for function annotations, or a
> decorator. I imagine both cases would look rather pretty
>
> def func(**kwargs: ordered):
> ...
Guido has more or less rejected annotations because checking for an
anotation would slow down every function call for the benefit of very few.
> @ordered_kwargs
> def func(**kwargs):
> ...
Returning a function with a custom ordered kwargs .__call__ method would
not affect normal functions. func.__class__ cannot be changed from
Python code (non-heap type) but I don't know about from C. In any case,
the attributes (components) of func could be fed to an okw_function
(ordered keyword function) class to produce an new object.
The decorator approach immediately fails for a system without the
decorator. Since it should only be used for funcs that require the
ordering, I think that would be appropriate.
tjr
More information about the Python-ideas
mailing list