[PEAK] AmbiguousMethod using PEAK-Rules
Scott Graham
sgraham at gmail.com
Wed Jan 23 17:08:49 EST 2008
Hi, I was just trying out PEAK-Rules, which I installed by doing:
easy_install svn://svn.eby-sarna.com/svnroot/BytecodeAssembler
easy_install svn://svn.eby-sarna.com/svnroot/PEAK-Rules
Consider the following code: (taken from
http://www.eby-sarna.com/pipermail/peak/2008-January/002825.html)
------------
from peak.rules import *
@abstract
def f(a,b):
"""A function"""
@when(f, (int, str))
def f_int_str(a, b):
print "f_int_str: %s %s" % (a, b)
@when(f, (str, int))
def f_str_int(a, b):
print "f_str_int: %s %s" % (a, b)
@when(f, "isinstance(a,str) and isinstance(b, int) and b==42")
def f_str_42(a, b):
print "f_str_42: %s %s" % (a, b)
f(4, "stuff")
f("stuff", 4)
f("stuff", 42)
------------
I was hoping all 3 functions would be called in turn, but I get:
f_int_str: 4 stuff
f_str_int: stuff 4
Traceback (most recent call last):
File "x.py", line 21, in <module>
f("stuff", 42)
File "<generated code>", line 0, in f
File "build/bdist.linux-i686/egg/peak/rules/core.py", line 214, in __call__
peak.rules.core.AmbiguousMethods: ([Method(<function f_str_int at
0xb7b0080c>, Signature([Test(IsInstance(Local('a')), Class(<type
'str'>, True)), Test(IsInstance(Local('b')), Class(<type 'int'>,
True))]), 41, None), Method(<function f_str_42 at 0xb7b00c6c>,
Signature([Test(IsInstance(Local('a')), Class(<type 'str'>, True)),
Test(IsInstance(Local('b')), Class(<type 'int'>, True)),
Test(Comparison(Local('b')), Value(42, True))]), 42, None)], ('stuff',
42), {})
Am I doing something wrong/illegal, or is this just a symptom of me
grabbing code that's not quite working?
thanks,
scott
More information about the PEAK
mailing list