[Python-ideas] parameter omit
Georg Brandl
g.brandl at gmx.net
Fri May 11 09:24:57 CEST 2007
Aaron Brady schrieb:
>> Is that really what you want? I thought you wanted this to work for
>> all functions...
>>
>> STeve
>
> You want to see the worked example again. Voila.
>
> def f( a,b=None,c='abc' ):
> print a,b,c
>
> default= object()
> def call_wrapper( callable, *args, **kwargs ):
> args=list(args)
> for i,j in enumerate( args ):
> if j is default:
> offset= callable.func_code.co_argcount-\
> len(callable.func_defaults)
> args[i]= callable.func_defaults[i-offset]
> return callable( *args,**kwargs )
>
> call_wrapper( f,0,default,'def' )
> call_wrapper( f,0,'somebody',default )
>
> #and output is:
> 0 None def
> 0 somebody abc
Fine, and now go ahead and patch this into the interpreter. I fear that
if you don't, nobody will.
IMHO this proposal is not completely bad, and as we can see there are
cases where it can help (albeit rare cases -- try to find one in the
standard library). But to assign a special meaning to a regular object
in this way (you can use it all the way you want, but once you call
something with it, it will be magically replaced) is a precedent in
Python, and I wouldn't have much hope for it.
But let this not hinder you to write a patch and bring it up on python-dev.
Georg
More information about the Python-ideas
mailing list