问题描述
我试图在 python 中声明具有唯一值的标记:
from enum import (
auto,Enum,unique
)
from typing import NamedTuple
@unique
class TokenType(Enum):
ASSIGN = auto()
COMMA = auto()
EOF = auto()
FUNCTION = auto()
IDENT = auto()
ILLEgal = auto()
INT = auto()
LBRACE = auto()
LET = auto()
LPAREN = auto()
PLUS = auto()
RBRACE = auto()
RPAREN = auto()
SEMICOLON = auto()
class Token(NamedTuple):
token_type: TokenType
literal: str
def __str__(self) -> str:
return f'Type: {self.token_type},Literal: {self.literal}'
但我收到了这个pylint错误:
继承'NamedTuple',这不是一个class.pylint(inherit-non-class)
解决方法
如评论中所述:
这是 Pylint 中的一个悬而未决的问题:https://github.com/PyCQA/pylint/issues/3876
该问题已在 astroid 上游项目中修复。 我可以通过升级来解决这个问题:
pip install astroid==2.5