Odd handling of type.__init__ bases

Discussion in 'Python' started by quick@sparq.org, Feb 28, 2008.

  1. Guest

    I encountered an oddity in attempting to use a metaclass to perform mix-in
    inheritance for classes. I've attached a small demonstration file. Have I
    misunderstood the bases argument for type.__init__ or should this be submitted
    as a bug?

    Python 2.5 (r25:51908, Feb 22 2007, 19:05:27)
    [GCC 4.1.2] on linux2

    -KQ





    -------------------------------------------------
    This mail sent through IMP: http://horde.org/imp/
    , Feb 28, 2008
    #1
    1. Advertising

  2. On Feb 28, 10:50 pm, wrote:
    > I encountered an oddity in attempting to use a metaclass to perform mix-in
    > inheritance for classes.  I've attached a small demonstration file.  Have I
    > misunderstood the bases argument for type.__init__ or should this be submitted
    > as a bug?


    After a quick look at your example:

    * you are mixing classic classes (abase) and new-style classes (A and
    B), which often creates problems.

    * type.__init__ does not set the base classes, type.__new__ does
    this. What you want to achieve could be done with:

    class meta3(type):
    def __new__(cls, name, bases, dict):
    bases += (abase,)
    return type.__new__(cls, name, bases, dict)

    HTH

    --
    Arnaud
    Arnaud Delobelle, Feb 28, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Replies:
    2
    Views:
    447
    Steven Bethard
    Feb 16, 2005
  2. Kent Johnson
    Replies:
    7
    Views:
    887
    Jan Niklas Fingerle
    Feb 12, 2006
  3. Michael Speer

    Odd behavior with odd code

    Michael Speer, Feb 16, 2007, in forum: C Programming
    Replies:
    33
    Views:
    1,069
    Richard Heathfield
    Feb 18, 2007
  4. Jean-Louis Leroy
    Replies:
    4
    Views:
    313
    Bo Persson
    Mar 5, 2009
  5. Ramchandra Apte
    Replies:
    17
    Views:
    330
    Manuel Pégourié-Gonnard
    Sep 30, 2012
Loading...

Share This Page