Python 中的内置 类 元类
Built-in classes metaclass in Python
是否有任何不是 type
元类实例的内置 Python 类?
>>> type(list)
<type 'type'>
>>> type(dict)
<type 'type'>
>>> type(some_builtin_python_class)
<type 'some_type_other_than_type'>
取决于您所说的 "built-in" 是什么意思。如果您的意思是 C-implemented(在 CPython 中)类 作为内置函数公开(在 builtin
中),那么不,其中 none 具有不同的元类。*
但在 stdlib 中肯定有 类。例如:
>>> type(collections.abc.Iterable)
abc.ABCMeta
澄清一下:其他 meta类 当然是 sub类 类型,所以,根据正常的继承规则,isinstance(Iterable, type)
仍然是正确的——但事实并非如此type(Iterable) == type
。您在问题中要求的是 type(T)
returns <type 'some_type_other_than_type'>
.
类型
* 不在 3.x 中,无论如何。 2.x 中的情况有所不同,那里有经典的 类,并且曾几何时,"fake classes" 实际上是看起来像 type
实例但实际上不是的函数,并在调用时返回隐藏 type
实例的实例。
是否有任何不是 type
元类实例的内置 Python 类?
>>> type(list)
<type 'type'>
>>> type(dict)
<type 'type'>
>>> type(some_builtin_python_class)
<type 'some_type_other_than_type'>
取决于您所说的 "built-in" 是什么意思。如果您的意思是 C-implemented(在 CPython 中)类 作为内置函数公开(在 builtin
中),那么不,其中 none 具有不同的元类。*
但在 stdlib 中肯定有 类。例如:
>>> type(collections.abc.Iterable)
abc.ABCMeta
澄清一下:其他 meta类 当然是 sub类 类型,所以,根据正常的继承规则,isinstance(Iterable, type)
仍然是正确的——但事实并非如此type(Iterable) == type
。您在问题中要求的是 type(T)
returns <type 'some_type_other_than_type'>
.
* 不在 3.x 中,无论如何。 2.x 中的情况有所不同,那里有经典的 类,并且曾几何时,"fake classes" 实际上是看起来像 type
实例但实际上不是的函数,并在调用时返回隐藏 type
实例的实例。