You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by Laurens Van Houtven <lv...@laurensvh.be> on 2009/06/21 00:30:39 UTC

py:twisted not creating new-style classes

Hi!


I've noticed that the classes generated by py:twisted aren't
new-style. Is there a reason why the classes need to be old-style, or
would it be possible to just turn class Whatever: into class
Whatever(object) and add a super(Whatever,self).__init__(self) to the
generated classes' __init__s?

lvh

Re: py:twisted not creating new-style classes

Posted by Laurens Van Houtven <lv...@laurensvh.be>.
Cool, thanks, I didn't know that existed :-D

Also, isn't part of the point of newstyle classes that you can just put:
super(ThisClass, self).__init__(self)
everywhere and that your entire inheritance lattice is guaranteed to
work (well, every __init__ will be called at least...)? Or maybe I'm
missing something Thrift-generated code specific, like I said, I don't
know anything about Thrift (but I'm liking it more and more every
passing minute) :-)

Also: does anyone know of any existing open source projects that use
thrift --gen py:twisted,new_style that I could take a look at (mainly
the Twisted bit, really). The generated servicename-remote script is a
big help, but more examples are always nice.


Thanks for the help
Laurens

On Mon, Jun 22, 2009 at 11:57 AM, Terry Jones<te...@jon.es> wrote:
> Hi Laurens
>
>>>>>> "Laurens" == Laurens Van Houtven <lv...@laurensvh.be> writes:
> Laurens> I've noticed that the classes generated by py:twisted aren't
> Laurens> new-style.
>
> Use
>
>  thrift --gen py:twisted,new_style
>
> to get new-style classes. I've been meaning to file a ticket for an
> addition to the class specification, I guess via something like
>
>    struct myclass {
>        1:i32 xxx,
>    } (python.superclass = "otherclass")
>
> that would allow one to specify the parent class. Then you could call
> __init__ in super, and perhaps not generate a __repr__ (to allow the parent
> to determine how instances should be printed), and maybe other things.
>
> Terry
>

Re: py:twisted not creating new-style classes

Posted by Terry Jones <te...@jon.es>.
Hi Laurens

>>>>> "Laurens" == Laurens Van Houtven <lv...@laurensvh.be> writes:
Laurens> I've noticed that the classes generated by py:twisted aren't
Laurens> new-style.

Use

  thrift --gen py:twisted,new_style

to get new-style classes. I've been meaning to file a ticket for an
addition to the class specification, I guess via something like

    struct myclass {
        1:i32 xxx,
    } (python.superclass = "otherclass")

that would allow one to specify the parent class. Then you could call
__init__ in super, and perhaps not generate a __repr__ (to allow the parent
to determine how instances should be printed), and maybe other things.

Terry