[英]Python3.7: Metaclassing from Tuple base class, receiving Type error
I am trying to create metaclass:我正在尝试创建元类:
from typing import Tuple
class StructMeta(Tuple):
pass
class Struct(metaclass=StructMeta):
pass
print(type(Struct))
Execute:执行:
Traceback (most recent call last):
File "main.py", line 9, in <module>
class Struct(metaclass=StructMeta):
TypeError: tuple expected at most 1 argument, got 3
Do not understand why this error?不明白为什么会出现这个错误?
typing.Tuple
appears to be a subclass of tuple
, which only takes one argument, an iterable. typing.Tuple
似乎是tuple
的子类,它只接受一个参数,一个可迭代的。
When creating a class, Python passes 3 arguments to its metaclass: the class name, a tuple of base classes, and a dict representing the class body. When creating a class, Python passes 3 arguments to its metaclass: the class name, a tuple of base classes, and a dict representing the class body.
It's not really possible to use typing.Tuple
as a metaclass.将typing.Tuple
用作元类实际上是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.