What are metaclass bases in python?
<p>I'm trying to extend django-allauth to do something specific to my projects. I'm basically trying to write my own wrapper on top of django-allauth, and want the installation, configuration and other stuff to be quite similar to allauth.<br>
For this, I started with extending <code>AppSettings</code> class from <code>allauth/accounts/app_settings.py</code>. I created my own <code>app_settings.py</code> did something like this:</p>

<pre><code>from allauth.account import app_settings as AllAuthAppSettings
class MyAppSettings (AllAuthAppSettings):
     def __init__(self, prefix):
         # do something
</code></pre>

<p>Also, at the end of the app_settings.py, I simply put the following (copying it from django-allauth itself):</p>

<pre><code>import sys
my_app_settings = MyAppSettings('MY_PREFIX_')
my_app_settings.__name__ = __name__
sys.modules[__name__] = my_app_settings
</code></pre>

<p>Now, when I start my project, it gives me the following error:</p>

<pre><code>TypeError: Error when calling the metaclass bases
    __init__() takes exactly 2 arguments (4 given)
</code></pre>

<p>Honestly, I'm quite new to the python-django world, and don't really understand what's happening in those last 4 lines.<br></p>

<p>What is <em>metaclass bases</em>? What are the 4 arguments that are being passed to it? How do I make this flow work?</p>

<p>Any help would be highly appreciated.</p>

<p>Update: Here's the stack trace:</p>

<pre><code>Unhandled exception in thread started by &lt;function wrapper at 0x104146578&gt;
Traceback (most recent call last):
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/user/anaconda/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/user/anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/user/myproject/my_app/models.py", line 18, in &lt;module&gt;
    from .model_managers import *
  File "/Users/user/myproject/my_app/model_managers.py", line 89, in &lt;module&gt;
    from . import app_settings
  File "/Users/user/myproject/my_app/app_settings.py", line 9, in &lt;module&gt;
TypeError: Error when calling the metaclass bases
    __init__() takes exactly 2 arguments (4 given)
</code></pre>

<p>It doesn't look like you should be able to inherit from <code>AllAuthAppSettings</code></p>

<p>The <code>django-allauth</code> package is doing some very ugly python magic</p>

<pre><code>import sys  # noqa
app_settings = AppSettings('ACCOUNT_')
app_settings.__name__ = __name__
sys.modules[__name__] = app_settings
</code></pre>

<p>Basically, when you import the <code>app_settings</code> module, it creates an instance of the <code>AppSettings</code> class, renames it to the name of the <code>app_settings</code> module, and then <em>replaces the imported module with the instance of the class</em>!</p>

<p>You cannot inherit from class instances.  I'm guessing you want to inherit from then non-instantiated <code>AppSettings</code> class.  To do that, you need to inherit from the <code>class</code> of <code>app_settings</code>, not <code>app_settings</code> directly</p>

<pre><code>from allauth.account import app_settings as AllAuthAppSettings


class MyAppSettings(AllAuthAppSettings.__class__):
    ...
</code></pre>

<p>I don't think you should need to copy those lines from the end of the <code>app_settings</code> module to hack your module into a class.</p>

python django class metaclass