[PEAK] Rules clarification

Sergey Schetinin maluke at gmail.com
Fri Feb 15 11:47:43 EST 2008

I've noticed that "when" function accepts anything as it's second
parameter (not just tuples), what does this declaration would mean
then (maybe nothing and it should throw an exception?)

>>> from peak.rules import *
>>> @abstract
... def test(foo):
...     pass
>>> @when(test, int) # <--------- this is what I'm talking about
... def test_int(foo):
...     print foo

I'd think non tuples would be used to match the first argument, but
that's not true:

>>> test(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in test
  File "<stdin>", line 1, in test
  File "c:\python25\lib\site-packages\peak_rules-0.3-py2.5.egg\peak\rules\core.p
y", line 547, in callback
    return f(*args)
  File "c:\python25\lib\site-packages\peak_rules-0.3-py2.5.egg\peak\rules\core.p
y", line 214, in __call__
    raise self.__class__(*self.args+(args,kw))  # XXX
peak.rules.core.NoApplicableMethods: ((0,), {})

Best Regards,
Sergey Schetinin

http://s3bk.com/ -- S3 Backup
http://word-to-html.com/ -- Word to HTML Converter

More information about the PEAK mailing list