Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:55:54+00:00 2026-06-02T04:55:54+00:00

Say I have a class A , B and C . Class A and

  • 0

Say I have a class A, B and C.

Class A and B are both mixin classes for Class C.

class A( object ):
    pass
class B( object ):
    pass
class C( object, A, B ):
    pass

This will not work when instantiating class C. I would have to remove object from class C to make it work. (Else you’ll get MRO problems).

TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases B, object, A

However, my case is a bit more complicated. In my case class C is a server where A and B will be plugins that are loaded on startup. These are residing in their own folder.

I also have a Class named Cfactory. In Cfactory I have a __new__ method that will create a fully functional object C. In the __new__ method I search for plugins, load them using __import__, and then assign them to C.__bases__ += (loadedClassTypeGoesHere, )

So the following is a possibility: (made it quite abstract)

class A( object ):
    def __init__( self ): pass
    def printA( self ):   print "A"
class B( object ):
    def __init__( self ): pass
    def printB( self ):   print "B"
class C( object ):
    def __init__( self ):  pass
class Cfactory( object ):
    def __new__( cls ):
        C.__bases__ += ( A, )
        C.__bases__ += ( B, )
        return C()

This again will not work, and will give the MRO errors again:

TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, A

An easy fix for this is removing the object baseclass from A and B. However this will make them old-style objects which should be avoided when these plugins are being run stand-alone (which should be possible, UnitTest wise)

Another easy fix is removing object from C but this will also make it an old-style class and C.__bases__ will be unavailable thus I can’t add extra objects to the base of C

What would be a good architectural solution for this and how would you do something like this? For now I can live with old-style classes for the plugins themselves. But I rather not use them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:55:56+00:00Added an answer on June 2, 2026 at 4:55 am

    Think of it this way — you want the mixins to override some of the behaviors of object, so they need to be before object in the method resolution order.

    So you need to change the order of the bases:

    class C(A, B, object):
        pass
    

    Due to this bug, you need C not to inherit from object directly to be able to correctly assign to __bases__, and the factory really could just be a function:

    class FakeBase(object):
        pass
    
    class C(FakeBase):
        pass
    
    def c_factory():
        for base in (A, B):
            if base not in C.__bases__:
                C.__bases__ = (base,) + C.__bases__
        return C()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three classes: class X{}; class Y{}; class Both : public X,
say I have: class Test { public static int Hello = 5; } This
Say I have this class: class myclass { public int Field1{ get; set; }
Say I have this class: public class Account { public int AccountID { get;
Let's say I have: class myClass std::list<myClass> myList where myClass does not define the
Say I have a class like this: class Person { private $value; public function
Say we have this hyper simple class hierchy: public class SomeMath { public int
Long story short Say I have the following code: // a class like this
Lets say I have : (this class Is OK) class CCheckSystemEndianess { private: int
I have a class that represents some business object, such as this: Public Class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.