本文介绍了Python的内置__build_class__有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python 3.1中,builtins模块中有一个我不知道的新内置函数:

In Python 3.1, there is a new builtin function I don't know in the builtins module:

__build_class__(...)
    __build_class__(func, name, *bases, metaclass=None, **kwds) -> class

    Internal helper function used by the class statement.

此功能有什么作用?如果它是内部的,为什么必须在内置文件中? type(name, bases, dict)函数有什么区别?

What does this function do? Why must it be in builtins if it's internal? What is the difference to the type(name, bases, dict) function?

推荐答案

编译 PEP 3115 元类

Compiling the PEP 3115 metaclass

Guido van Rossum说:

所以我认为 这是对新的(隐藏的)调用 内置函数,名为 __build_class__.然后,这个类定义:

So I think it would be acceptable to this into a call to a new (hidden) built-in function, named __build_class__. Then that this class definition:

  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>是用于 班级的身体.

where <func> is a function object for the class body.

这篇关于Python的内置__build_class__有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:32