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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:53:05+00:00 2026-05-29T11:53:05+00:00

I have a metaclass: class MyMeta(type): def __init__(cls, name, bases, dct): # Do something

  • 0

I have a metaclass:

class MyMeta(type):
    def __init__(cls, name, bases, dct):
        # Do something
        ...

        return super(MyMeta, cls).__init__(cls, name, bases, dct)

and a class:

class MyClass(object):
    __metaclass__ = MyMeta

When I use these I get the following error:

TypeError: Error when calling the metaclass bases
    type.__init__() takes 1 or 3 arguments

What’s the problem, and why does type.__init__() take a precisely variable number of arguments?

  • 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-29T11:53:07+00:00Added an answer on May 29, 2026 at 11:53 am

    The problem is that in the upgrade from python 2.5 to python 2.6 type.__init__() was changed so that you are no longer required to pass in cls. So simply make the super call:

    return super(MyMeta, cls).__init__(name, bases, dct)
    

    Another solution is to avoid the super call altogether and do this (although it’s a little less nice):

    return type.__init__(cls, name, bases, dct)
    

    And everything will work fine (in python >= 2.6).

    As to why type.__init__() can take differing numbers of arguments, check out the documentation. It’s so that as well as using it as a constructor, you can call type(myobject) and it will return the type of myobject:

    >>> number = 1
    >>> type(number)
    <type 'int'>
    >>> type('my string')
    <type 'str'>
    

    See What is a metaclass in Python? for more information on metaclasses and type.

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

Sidebar

Related Questions

I have a python class with emulated static properties via a metaclass: class MyMeta(type):
Updated I have the following custom field class: class Binary(models.Field): __metaclass__ = models.SubfieldBase def
I have a domain class like: class MyDomainClass{ String name } And an interface
I have two questions: Does method f_1 belong to the metaclass anonymous class? Does
I have a declarative base class Entity which defines the column name as polymorphic,
Have a look at the following code: class A(object): defaults = {'a': 1} def
Lets assume we have a class in python: class A(object): def __del__(self): print Del!
I define an metaclass class MyMetaClass extends DelegatingMetaClass { MyMetaClass(Class theClass){ super(theClass) println theClass
I have read posts like these: What is a metaclass in Python? What are
Today I have come across a surprising definition of a metaclass in Python here

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.