pylint:False“试图解开非序列(解开未包装的未序列)”

发布于 2025-02-13 08:57:20 字数 1126 浏览 0 评论 0原文

我已经看到有关不正确的皮特“解开未包装”消息的线程,但是这些线程会有理由(例如返回无 /返回(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文