Hi Armin, Thanks for the help! I tried your suggestion, and I get the following error when I try to call that function on a wrapped object (instead of _my_extra_dict, I named the attribute "rbflags" and called the function get_rbflags) :
Attribute 'rb_flags' on <ClassDef 'pypy.interpreter.baseobjspace.W_Root'> should be read-only. This error can be caused by another 'getattr' that promoted the attribute here; the list of read locations is: (pypy.interpreter.baseobjspace:39)W_Root.get_rbflags v1066 = setattr(self_275, ('rb_flags'), v1065) In <FunctionGraph of (pypy.interpreter.baseobjspace:39)W_Root.get_rbflags at 0x65b54e90>: Happened at file /home/ubuntu/pypy2-v5.3.1-src/pypy/interpreter/baseobjspace.py line 41 ==> self.rb_flags = {} Known variable annotations: self_275 = SomeInstance(can_be_None=False, classdef=pypy.interpreter.baseobjspace.W_Root) v1065 = SomeOrderedDict(dictdef=<{SomeImpossibleValue(): SomeImpossibleValue()}>) Processing block: block@15 is a <class 'rpython.flowspace.flowcontext.SpamBlock'> in (pypy.interpreter.baseobjspace:39)W_Root.get_rbflags containing the following operations: v1065 = newdict() v1066 = setattr(self_275, ('rb_flags'), v1065) --end-- Frank On Fri, Dec 16, 2016 at 2:20 PM, Carl Friedrich Bolz <cfb...@gmx.de> wrote: > Hi Frank, > > Yes, you'll get an instance variable that way. > > Cheers, > > Carl Friedrich > > On December 16, 2016 6:05:56 PM GMT+01:00, Frank Wang <fra...@mit.edu> > wrote: > >> Hi Armin, >> >> Thanks for the suggestion! I'll see if that works. Just to make sure. >> This will give me an instance variable? I need values of the extra dict to >> be different for different instantiations of W_Root. >> >> Frank >> >> On Fri, Dec 16, 2016 at 11:19 AM, Armin Rigo <armin.r...@gmail.com> >> wrote: >> >>> Hi Frank, >>> >>> On 15 December 2016 at 21:06, Frank Wang <fra...@mit.edu> wrote: >>> > Right now, I know W_Root has no __init__ function, and when I try to >>> add >>> > one. I run into all sorts of problems because TypeDef calls >>> W_Root.__new__ >>> > with some parameters, but "new" function seems to be called nowhere >>> else. >>> >>> I suspect there is no clean way to add a __init__() method to W_Root. >>> You could use default attributes instead: >>> >>> class W_Root: >>> _my_extra_dict = None >>> >>> def get_extra_dict(self): >>> if self._my_extra_dict is None: >>> self._my_extra_dict = {} >>> return self._my_extra_dict >>> >>> >>> >>> A bientôt, >>> >>> Armin. >>> >> >> ------------------------------ >> >> pypy-dev mailing list >> pypy-dev@python.org >> https://mail.python.org/mailman/listinfo/pypy-dev >> >>
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev