【发布时间】:2017-06-18 22:21:05
【问题描述】:
我正在尝试定义一个自定义元类型以用于类型提示。例如
print(Tuple[int, str, bool])
print(CustomType[int, str, bool])
显然,第一行工作正常。我将如何实现CustomType,以便它也可以工作?我试过这个:
class CustomType(Tuple):
pass
并得到错误TypeError: __main__.CustomType is not a generic class。
我的目标是通过额外的类方法对 Tuple 进行专业化
【问题讨论】:
标签: python python-3.x generics type-hinting