以下dataclass
条:
from abc import ABC
from collections.abc import Mapping
from dataclasses import dataclass, field
@dataclass(eq=True, order=True, frozen=True)
class Expression(Node, ABC):
def node(self):
raise NotImplementedError
用作以下对象的基类:
@dataclass(eq=True, frozen=True)
class HashLiteral(Expression):
pairs: Mapping[Expression, Expression]
...
Node
的定义如下:
@dataclass(eq=True, frozen=True)
class Node:
def __str__(self) -> str:
raise NotImplementedError
当try 使用HashLiteral
类时,我得到一个错误:
pairs: Mapping[Expression, Expression]
TypeError: 'ABCMeta' object is not subscriptable
我对上面pairs
的注释有什么问题?