[PEAK] PEAK-Rules and PyPy

Alain Poirier alain.poirier at net-ng.com
Tue Oct 16 12:48:07 EDT 2012


Le 16 oct. 2012 à 18:26, Marcin Tustin <marcin.tustin at gmail.com> a écrit :

> Please see: http://docs.python.org/library/__builtin__.html?highlight=__builtins__

Thanks Marcin. I see from the 'CPython implementation detail' note, '__builtins__'
can be a module or a dict. Ok, so I added a check to use '__builtins__.__dict__' if
'__builtins__' is a module and now I've got:

>>>> from peak.rules import predicates
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/private/tmp/p/site-packages/DecoratorTools-1.8-py2.7.egg/peak/util/decorators.py", line 617, in tracer
    frm.f_locals[k] = callback(frm,k,v,old_locals)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 276, in callback
    register_for_class(None)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 270, in register_for_class
    _register_rule(f, pred, context, cls)
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 395, in _register_rule
    rules.add(parse_rule(Dispatching(gf).engine, pred, context, cls))
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 953, in parse_upgrade
    predicate, context, cls
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/core.py", line 685, in parse_rule
    def parse_rule(engine, predicate, context, cls):
  File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 606, in _parse_string
    maybe_bind(ctx.body, bindings), expr, ctx.actiontype, ctx.sequence
UnboundLocalError: local variable 'expr' referenced before assignment

which is strange because 'expr' is just defined some lines above.

> CPython implementation detail: Most modules have the name __builtins__ (note the 's') made available as part of their globals. The value of__builtins__ is normally either this module or the value of this modules’s __dict__ attribute. Since this is an implementation detail, it may not be used by alternate implementations of Python.
> 
> On Tue, Oct 16, 2012 at 12:22 PM, PJ Eby <pje at telecommunity.com> wrote:
> On Tue, Oct 16, 2012 at 11:18 AM, Alain Poirier
> <alain.poirier at net-ng.com> wrote:
> >   File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/predicates.py", line 595, in _parse_string
> >     b = CriteriaBuilder(engine.arguments, ctx.localdict, ctx.globaldict, __builtins__)
> >   File "/private/tmp/PEAK-Rules-0.5a1.dev-r2707/peak/rules/codegen.py", line 334, in __init__
> >     dict([(k,self.Const(v)) for k,v in ns.iteritems()]) for ns in namespaces
> > AttributeError: 'module' object has no attribute 'iteritems'
> >
> >
> > Do you think it could be possible to have a working PyPy version of Peak Rules?
> 
> It depends. It looks like the problem above is that __builtins__ in
> PyPy might be a module instead of a dictionary?  If so, that's
> probably a bug in PyPy that needs to be fixed.
> 
> There are likely to be other problems besides this one, but let's take
> them one at a time.  ;-)


More information about the PEAK mailing list