[pypy-dev] Adding init/variables to W_Root

Frank Wang frankw at mit.edu
Sun Dec 18 23:29:30 EST 2016


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 at 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 <cfbolz at 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 <frankw at 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.rigo at gmail.com>
>> wrote:
>>
>>> Hi Frank,
>>>
>>> On 15 December 2016 at 21:06, Frank Wang <frankw at 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 at python.org
>> https://mail.python.org/mailman/listinfo/pypy-dev
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20161218/5efa4e06/attachment.html>


More information about the pypy-dev mailing list