【发布时间】:2018-04-16 13:41:54
【问题描述】:
对于Transcrypt Python to JavaScript compiler 的3.7.1 版本,我目前正在使用新的@dataclass 装饰器。我曾预计 ==, !=, <, >, >=, <= 会得到支持,就像 the PEP's abstract 一样,但似乎并非如此:
from dataclasses import dataclass
@dataclass
class C:
x: int = 10
有些比较不起作用:
>>> c1 = C(1)
>>> c2 = C(2)
>>> c1 == c2 # ok
False
>>> c1 < c2 # crash
TypeError: '<' not supported between instances of 'C' and 'C'
除了== 和!= 之外,为什么不支持比较运算符?还是我忽略了什么?
【问题讨论】:
标签: python transcrypt python-3.7 python-dataclasses