What is the difference between type and type.__new__ in python?

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-04-09T15:32:43Z Indexed on 2010/04/09 15:53 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

I was writing a metaclass and accidentally did it like this:

class MetaCls(type):
    def __new__(cls, name, bases, dict):
        return type(name, bases, dict)

...instead of like this:

class MetaCls(type):
    def __new__(cls, name, bases, dict):
        return type.__new__(cls, name, bases, dict)

What exactly is the difference between these two metaclasses? And more specifically, what caused the first one to not work properly (some classes weren't called into by the metaclass)?

© Stack Overflow or respective owner

Related posts about python

Related posts about metaclass