Phyton Customary To Inherit Metaclasses From type?

I have been trying to understand python metaclasses, and so have been going through some sample code. As far as I understand it, a Python metaclass can be any callable. So, I can have my metaclass like

def metacls(clsName, bases, atts):
    ....
    return type(clsName, bases, atts)

However, I have seen a lot of people write their metaclasses in the following way:

class Metacls(type):
    def __new__(meta, clsName, bases, atts):
        ....
        return type.__new__(meta, clsName, bases, atts)

As far as I can see, these would both do the same thing. Is there any reason to use the base class instead? Is it customary?

Answer:1



Is there any way to view a function's doc string when writing Python in VIM? For instance: def MyFunction(spam): """A function that foobars the spam returns eggs""" return foobar(spam)....

Is there any way to view a function's doc string when writing Python in VIM? For instance: def MyFunction(spam): """A function that foobars the spam returns eggs""" return foobar(spam)....

I am having a problem during the installation of tkinter. I have version 2.7.11. I entered the pip install tkinter on dos but it shows the following message: collecting tkinter Could not find ...

I am having a problem during the installation of tkinter. I have version 2.7.11. I entered the pip install tkinter on dos but it shows the following message: collecting tkinter Could not find ...