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 6596969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:08:54+00:00 2026-05-25T18:08:54+00:00

I’ve been messing around with the dark arts of Python and there’s something I’d

  • 0

I’ve been messing around with the dark arts of Python and there’s something I’d like help understanding. Given a class Foo, here’s some ways I attempted to inherit from it:

  1. class A(Foo) — Works, unsurprizingly
  2. class B(Foo()) — works provided Foo has an appropriate __new__ method (which I provided)
  3. class C(Foo(), Foo) — works, under the same conditions as B
  4. class D(Foo, Foo()) — gives the famous metaclass error:

    Traceback (most recent call last):
       File “test.py”, line 59, in
            class D(Foo, Foo()):
    TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict)
    subclass of the metaclasses of all its bases

What exactly is it that causes this conflict? When I inherit from (Foo(), Foo) (instance first, class second) it works, but when I inherit from (Foo, Foo()) (class first, instance second), it doesn’t.

  • 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-05-25T18:08:54+00:00Added an answer on May 25, 2026 at 6:08 pm

    When you “inherent from an instance”, what you’re really doing is a strange way of using a metaclass. Normally, class objects are instances of type. In the case of class B above, it inherits from an instance of Foo. This is exactly what would happen if you defined a class with Foo as its metaclass, and then inherited from that.

    So my speculation as to what’s happening here is that Python is processing the base classes in reverse MRO order.

    Class C works because the first parent class to be processed is Foo, whose class is type. This means that the metaclass of D must be type, or some subclass thereof. Then Foo() is processed, whose class is Foo, which is a subclass of type, so everything’s fine.

    Class D fails because the first parent class to be processed is Foo(), which sets a constraint that D have a metaclass of Foo (or subclass). Then Foo comes along, whose class type is not a subclass of Foo.

    That is a complete guess, but you could try and see if the Python documentation on metaclasses requires when you multiply inherit from two classes with different metaclasses, where the metaclasses involved have a subtype relationship, that you put them in a particular order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.