[PEAK] dispatch Problem?

Jay Parlar parlar at gmail.com
Fri Jan 21 10:14:49 EST 2005


Am I doing something wrong here, or is this a bug in the dispatch module?

Essentially, I want to check if an object attribute is evaluating to
True or not, ie.

>>> import dispatch
>>> @dispatch.generic()
... def foo(x): pass
...
>>> @foo.when("x.bar")
... def foo(x): print "x.bar is some sort of true"
...
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 690, in when
   return self._decorate(cond)
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 577, in _deco
rate
   cond = self.parseRule(cond,frame=frame) or cond
 File "<string>", line 10, in parseRule
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 400, in parse
Rule
   return self.parse(rule, frame.f_locals, frame.f_globals)
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 242, in parse

   return parse_expr(expr_string,builder)
 File "c:\Python24\Lib\site-packages\dispatch\ast_builder.py", line 383, in par
se_expr
   return build(builder, parser.expr(expr).totuple(1)[1])
 File "c:\Python24\Lib\site-packages\dispatch\ast_builder.py", line 378, in bui
ld
   return production[nodelist[0]](builder,nodelist)
 File "c:\Python24\Lib\site-packages\dispatch\ast_builder.py", line 181, in pow
er
   return builder.Getattr(nodelist, node[2][1])
 File "c:\Python24\Lib\site-packages\dispatch\predicates.py", line 669, in meth
od
   return expressionSignature(op(self.expr_builder,*args), self.mode)
 File "<string>", line 5, in expressionSignature
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 313, in __get
item__
   node = dispatch_function(get(expr), node)
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 301, in get
   f = cache[expr_id] = f(*map(get,args))
 File "c:\Python24\Lib\site-packages\dispatch\functions.py", line 301, in get
   f = cache[expr_id] = f(*map(get,args))
 File "<string>", line 1, in <lambda>
AttributeError: 'Getattr' object has no attribute 'argexprs'
>>>

For now, I have to do:

>>> @foo.when("getattr(x, 'bar', False)")
... def foo(x): print "x.bar is some sort of true"
...
>>>

but that's not entirely the prettiest thing I've ever seen.

This was run with the latest version of PEAK from CVS.

Jay P.



More information about the PEAK mailing list