trying to run peak-rules on python3

HervĂ© Coatanhay <[email protected]> Mon, 18 Mar 2013 10:56:18 -0700
Newsgroups gmane.comp.python.peak
Message-ID <CAPq7H1a06BuCwscQmfattDXhpUa_g9YLQNa3LjcUynZeqcSvmw@mail.gmail.com>
--===============0551328652==
Content-Type: multipart/alternative; boundary=047d7bdc9fd2bf8d5204d836b492

--047d7bdc9fd2bf8d5204d836b492
Content-Type: text/plain; charset=UTF-8

Hi,

I'm trying to port nagare to python3. I managed to run a simple application
but I had to make some changes in few PEAK packages.

Here is how I proceeded:
1) run 2to3 on these packages
2) fix remaining "obvious" issue (no more `file` builtin, package renaming,
...)
3) fix types/new/ast changes made in python3
4) remove rules on old-style classes

Here is the code produced by this very naive approach
https://bitbucket.org/Alzakath/peak-py3.

As a result, PEAK-Rules seems to work when I only use dispatch on type. But
it seems predicate dispatch is not working, for example:

from peak.rules import when

def f(x):
    print('default')

@when(f, 'x == 3')
def f(x):
    print("I'm an integer")

f('test')
f(3)


Traceback (most recent call last):
  File "peak-rules_test_ko.py", line 6, in <module>
    @when(f, 'x == 3')
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/DecoratorTools-1.8/peak/util/decorators.py",
line 644, in do_decorate
    frame, getattr(f,'__name__',None), f, frame.f_locals
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 278, in callback
    register_for_class(None)
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 272, in register_for_class
    _register_rule(f, pred, context, cls)
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 398, in _register_rule
    rules.add(parse_rule(Dispatching(gf).engine, pred, context, cls))
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 689, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 592, in callback
    return f(*args, **kw)
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py",
line 952, in parse_upgrade
    from peak.rules.predicates import IndexedEngine
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/predicates.py",
line 4, in <module>
    from .criteria import *
  File
"/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/criteria.py",
line 145, in <module>
    inequalities = {
TypeError: nonempty __slots__ not supported for subtype of 'int'

Does anyone tried to port peak-rules to python3 ? Do you have any advice on
the right way to do it ? Or even hints on what I'm missing ?

Cheers,
Herve

--047d7bdc9fd2bf8d5204d836b492
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div><div><div>Hi,<br><br></div>I&#39;=
m trying to port nagare to python3. I managed to run a simple application b=
ut I had to make some changes in few PEAK packages.<br><br></div>Here is ho=
w I proceeded:<br>

</div>1) run 2to3 on these packages<br></div>2) fix remaining &quot;obvious=
&quot; issue (no more `file` builtin, package renaming, ...)<br></div>3) fi=
x types/new/ast changes made in python3<br></div><div>4) remove rules on ol=
d-style classes<br>

</div><div><br></div>Here is the code produced by this very naive approach =
<a href=3D"https://bitbucket.org/Alzakath/peak-py3" target=3D"_blank">https=
://bitbucket.org/Alzakath/peak-py3</a>.<br><br></div>As a result, PEAK-Rule=
s seems to work when I only use dispatch on type. But it seems predicate di=
spatch is not working, for example:<br>

<br>from peak.rules import when<br><br>def f(x):<br>=C2=A0=C2=A0=C2=A0 prin=
t(&#39;default&#39;)<br><br>@when(f, &#39;x =3D=3D 3&#39;)<br>def f(x):<br>=
=C2=A0=C2=A0=C2=A0 print(&quot;I&#39;m an integer&quot;)<br><br>f(&#39;test=
&#39;)<br>f(3)<br><br><br>Traceback (most recent call last):<br>

=C2=A0 File &quot;peak-rules_test_ko.py&quot;, line 6, in &lt;module&gt;<br=
>=C2=A0=C2=A0=C2=A0 @when(f, &#39;x =3D=3D 3&#39;)<br>=C2=A0 File &quot;/Us=
ers/herve/Documents/workspace/nagare/python3-ports/peak-py3/DecoratorTools-=
1.8/peak/util/decorators.py&quot;, line 644, in do_decorate<br>

=C2=A0=C2=A0=C2=A0 frame, getattr(f,&#39;__name__&#39;,None), f, frame.f_lo=
cals<br>=C2=A0 File &quot;/Users/herve/Documents/workspace/nagare/python3-p=
orts/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py&quot;, line 278=
, in callback<br>

=C2=A0=C2=A0=C2=A0 register_for_class(None)<br>=C2=A0 File &quot;/Users/her=
ve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r=
2713/peak/rules/core.py&quot;, line 272, in register_for_class<br>=C2=A0=C2=
=A0=C2=A0 _register_rule(f, pred, context, cls)<br>

=C2=A0 File &quot;/Users/herve/Documents/workspace/nagare/python3-ports/pea=
k-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py&quot;, line 398, in _re=
gister_rule<br>=C2=A0=C2=A0=C2=A0 rules.add(parse_rule(Dispatching(gf).engi=
ne, pred, context, cls))<br>

=C2=A0 File &quot;/Users/herve/Documents/workspace/nagare/python3-ports/pea=
k-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py&quot;, line 689, in par=
se_rule<br>=C2=A0=C2=A0=C2=A0 def parse_rule(engine, predicate, context, cl=
s):<br>=C2=A0 File &quot;/Users/herve/Documents/workspace/nagare/python3-po=
rts/peak-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/core.py&quot;, line 592,=
 in callback<br>

=C2=A0=C2=A0=C2=A0 return f(*args, **kw)<br>=C2=A0 File &quot;/Users/herve/=
Documents/workspace/nagare/python3-ports/peak-py3/PEAK-Rules-0.5a1.dev-r271=
3/peak/rules/core.py&quot;, line 952, in parse_upgrade<br>=C2=A0=C2=A0=C2=
=A0 from peak.rules.predicates import IndexedEngine<br>

=C2=A0 File &quot;/Users/herve/Documents/workspace/nagare/python3-ports/pea=
k-py3/PEAK-Rules-0.5a1.dev-r2713/peak/rules/predicates.py&quot;, line 4, in=
 &lt;module&gt;<br>=C2=A0=C2=A0=C2=A0 from .criteria import *<br>=C2=A0 Fil=
e &quot;/Users/herve/Documents/workspace/nagare/python3-ports/peak-py3/PEAK=
-Rules-0.5a1.dev-r2713/peak/rules/criteria.py&quot;, line 145, in &lt;modul=
e&gt;<br>

=C2=A0=C2=A0=C2=A0 inequalities =3D {<br>TypeError: nonempty __slots__ not =
supported for subtype of &#39;int&#39;<br><br><div>Does anyone tried to por=
t peak-rules to python3 ? Do you have any advice on the right way to do it =
? Or even hints on what I&#39;m missing ? <br>
</div><div><div><div><div><div><div><div><div><br></div><div>Cheers,<br></d=
iv><div>Herve<br></div></div></div></div></div></div></div></div></div>

--047d7bdc9fd2bf8d5204d836b492--

--===============0551328652==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
PEAK mailing list
[email protected]
http://www.eby-sarna.com/mailman/listinfo/peak
--===============0551328652==--