Search code examples
pythonclasstypespython-2.x

How to define a Python 2 class/function so that its type is "type"


When defining a class Foo, or function Bar, I get:

>>> import MethodType
>>> type(Foo)
classobj
>>> type(Bar)
function

>>> type(MethodType)
type

How do I define a class/function myself, so that its type is "type"?


Solution

  • You didn't inherit from object when defining your Foo class:

    class Foo(object):
        ...