Re: generic functions and keyword arguments

Vladimir Iliev <[email protected]>
Newsgroups gmane.comp.python.peak
Message-ID <[email protected]>
Phillip J. Eby написа:
> At 05:14 PM 8/2/2008 +0300, Vladimir Iliev wrote:
>> hi, can i somehow use keyword arguments with peak.rules based generic 
>> functions ?
> 
> Arguments passed by keyword are treated the same as arguments passed by 
> position, so e.g.:
> 
>  def a(b, c):
>      ...
> 
> can be called with "a(c=1,b=2)".   If you mean, can you do this:
> 
> 
>   def a(**kw):
> 
> and then test for whether the caller passed in b=2, you would use rules 
> like:
> 
>   @when(a, "'b' in kw and kw['b']==2")
> 
> in order to dispatch on arguments that are not part of the generic 
> function's "def" signature.

no, i just want to pass arguments that are not part of the signature 
through the gf.

if i do this:

@abstract
def func(x, **k):
     pass

@when(func, (str,))
def func_str(x, **k):
     print 'str'


func('x', y=5)

i'm getting TypeError: callback() got an unexpected keyword argument 'y'
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.