pylint:False“试图解开非序列(解开未包装的未序列)”
我已经看到有关不正确的皮特“解开未包装”消息的线程,但是这些线程会有理由(例如返回无 /返回(a,b))。但是我还没有看到这样的东西,也看不到皮革哭泣的原因。 代码如下,不确定数据级是否会弄乱事物,所以我包括它可以肯定:
class FunctionDescription(Protocol):
def get(self) -> Tuple[int, int]:
...
class SquareFunction:
def __init__(self, x):
self.x: int = x
def get(self) -> Tuple[int, int]:
return self.x, self.x**2
@dataclass
class FunctionPrinter:
function: FunctionDescription
def run(self):
y1, y2 = self.function() # <-- here pylint cries "unpacking-non-sequence"
print(y1, y2)
if __name__ == "__main__":
square = SquareFunction(x=5)
p = FunctionPrinter(function=square)
p.run()
有人知道为什么Pylint抱怨它?还是我如何使其“正确”? 谢谢您的投入!
编辑:
正如Brian所说:添加时没有PYLINT消息,在
。function> functiondescription.get
中提出notimplemplededError
有趣的是,当functionPrinter
不是数据级时:
class FunctionPrinter:
def __init__(self, function):
self.function: FunctionDescription = function
def run(self):
# as before
也没有皮层消息
I have seen few threads about incorrect pylint "unpacking-non-sequence" messages, but those would have reason (like return None / return (a, b) ). But I haven't seen anything like this and i don't see the reason for pylint crying.
The code is as follows, not sure if the dataclasses can mess with things, so i am including it to be sure:
class FunctionDescription(Protocol):
def get(self) -> Tuple[int, int]:
...
class SquareFunction:
def __init__(self, x):
self.x: int = x
def get(self) -> Tuple[int, int]:
return self.x, self.x**2
@dataclass
class FunctionPrinter:
function: FunctionDescription
def run(self):
y1, y2 = self.function() # <-- here pylint cries "unpacking-non-sequence"
print(y1, y2)
if __name__ == "__main__":
square = SquareFunction(x=5)
p = FunctionPrinter(function=square)
p.run()
Anyone has idea why pylint complains about it? Or how I can make it "correct" ?
Thank you for you input!
Edit:
As Brian said: no pylint message when added raise NotImplementedError
in FunctionDescription.get
.
Interestingly, when FunctionPrinter
is not a dataclass:
class FunctionPrinter:
def __init__(self, function):
self.function: FunctionDescription = function
def run(self):
# as before
there is no pylint message either
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论