Re: [Python-ideas] parameter omit

Steven Bethard [mailto:steven.bethard@gmail.com]
On 5/11/07, Aaron Brady <castironpi@comcast.net> wrote:
Nope, routine object. I defined it earlier:
paramdefault= object()
Yes, but how is it going to *work*? Say I wrote the function:: def foo(bar=1, baz=2): print bar, baz Now if I call that like:: foo(bar=paramdefault, baz=paramdefault) I'm going to see something like:: <object object at 0x009A0468> <object object at 0x009A0468> Is that really what you want? I thought you wanted this to work for all functions... STeve -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy

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

Aaron Brady schrieb:
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

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

Aaron Brady schrieb:
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
participants (3)
-
Aaron Brady
-
Georg Brandl
-
Steven Bethard