如何定义一个 python 函数使其类型为 "type"?

How to define a python function so its type is "type"?

定义 class Foo 或函数 Bar 时,我得到:

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

>>> type(MethodType)
type

我的问题是,如何自己定义一个class/function,使其类型为"type"?

非常感谢。

您在定义 Foo class 时没有从 object 继承:

class Foo(object):
    ...