Python: Metaclasses and __slots__?
<p>So, I am reading a bit about metaclasses in Python, and how <code>type()</code>'s three-argument alter-ego is used to dynamically create classes.  However, the third argument is usually a <code>dict</code> that initializes the to-be created class' <code>__dict__</code> variable.</p>

<p>If I want to dynamically create classes based on a metaclass that uses <code>__slots__</code> instead of <code>__dict__</code>, how might I do this?  Is <code>type()</code> still used in some fashion along with overriding <code>__new__()</code>?</p>

<p>As an FYI, I am aware of the proper uses for <code>__slots__</code>, to save memory when creating large numbers of a class versus abusing it to enforce a form of type-safety.</p>

<p><br />Example of a normal (new-style) class that sets <code>__metaclass__</code> and uses a <code>__dict__</code>:</p>

<pre><code>class Meta(type):
    def __new__(cls, name, bases, dctn):
        # Do something unique ...
        return type.__new__(cls, name, bases, dctn)

class Foo(object):
    __metaclass__ = Meta

    def __init__(self):
        pass
</code></pre>

<p><br />In the above, <code>type.__new__()</code> is called and the fourth argument (which becomes the third when actually used) creates a <code>__dict__</code> in <code>Foo</code>.  But if I wanted to modify <code>Meta</code> to include <code>__slots__</code>, then I have no dictionary to pass on to <code>type()</code>'s <code>__new__()</code> function (as far as I know -- I haven't tested any of this yet, just pondering and trying to find some kind of a use-case scenario).</p>

<p><strong>Edit:</strong> A quick, but untested guess, is to take a dict of the values to be put into the <code>__slots__</code> variables and pass it to <code>type.__new__()</code>.  Then add an <code>__init__()</code> to <code>Meta</code> that populates the <code>__slots__</code> variables from the dict.  Although, I am not certain how that dict would reach <code>__init__()</code>, because the declaration of <code>__slots__</code> prevents <code>__dict__</code> from being created unless <code>__dict__</code> is defined in <code>__slots__</code>...</p>
