Python的内置__build_class__有什么作用?
在Python 3.1中,模块中有一个我不知道的新内置函数builtins
:
__build_class__(...)
__build_class__(func, name, *bases, metaclass=None, **kwds) -> class
Internal helper function used by the class statement.
此功能有什么作用?如果它是内部的,为什么必须在内置文件中?功能有什么区别type(name, bases, dict)
?
-
编译 PEP 3115元类
PEP建议class语句接受关键字参数
*args
,和**kwds
语法以及位置基础。编译和执行这有点麻烦,但是我们在调用常规函数的代码中当然已经有了它。因此,我认为调用新的(隐藏)内置函数名为可以接受
__build_class__
。然后,这个类定义:class C(A, B, metaclass=M, other=42, *more_bases, *more_kwds): ...
会翻译成这样:
C = __build_class__(<func>, 'C', A, B, metaclass=M, other=42, *more_bases, *more_kwds)
<func>
类主体的功能对象在哪里。