是什么让 pylint 认为我的课程是抽象的? [英] What makes pylint think my class is abstract?

查看:38
本文介绍了是什么让 pylint 认为我的课程是抽象的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Python (2.5.2) 并没有真正支持抽象类.为什么 pylint 抱怨这个类是抽象类不是引用?"它会对抛出 NotImplementedError 的任何类执行此操作吗?

As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has NotImplementedError thrown?

我将每个类都放在自己的文件中,所以如果是这种情况,我想我别无选择,只能取消此消息,但我希望可能有另一种解决方法.

I have each class in its own file so if this is the case I guess I have no choice but to suppress this message but I am hoping there is maybe another way around it.

"""Package Repository interface."""


class PackageRepository(object):
    """Package Repository interface."""

    def __init__(self):
        self.hello = "world"

    def get_package(self, package_id):
        """
        Get a package by ID.
        """
        raise NotImplementedError( \
                "get_package() method has not been implemented")

    def get_packages(self):
        """
        Get all packages.
        """
        raise NotImplementedError( \
                "get_packages() method has not been implemented")

    def commit(self):
        """
        Commit all changes.
        """
        raise NotImplementedError( \
                "commit() method has not been implemented")

    def do_something(self):
        """
        Doing something.
        """
        return self.hello

<小时>

编辑

也许我应该澄清一下.我意识到这是一个抽象类,我很想使用 abstract 关键字,但据我所知,在 Python 中这些都不重要(至少在我目前使用的版本中),所以我没有费心做任何有趣的抽象技巧(就像那些在此处找到),然后将其忽略.

Perhaps I should clarify. I realize this is an abstract class and I would love to use the abstract keyword but as I understand it none of that matters in Python (at least in the version I am currently using) so I didn't bother doing any funny abstract tricks (like those found here) and simply left it out.

我很惊讶地看到 pylint 发现这是一个抽象类.是什么让 pylint 确定这是一个抽象类?它只是在寻找被抛出的 NotImplementedError 吗?

I was surprised to see that pylint picks up on the fact that this is an abstract class on its own. What makes pylint determine this is an abstract class? Is it simply looking for NotImplementedError being thrown somewhere?

推荐答案

FWIW,引发 NotImplementedError 足以让 pylint 认为这是一个抽象类(这是绝对正确的).来自 logilab.org/card/pylintfeatures:W0223:方法 %r 在类 %r 中是抽象的,但未被覆盖当抽象方法(即引发 NotImplementedError)在具体类中未被覆盖时使用.– Tobiesque 2 小时前

FWIW, raising NotImplementedError is enough to make pylint think this is an abstract class (which is absolutely correct). from logilab.org/card/pylintfeatures: W0223: Method %r is abstract in class %r but is not overridden Used when an abstract method (ie raise NotImplementedError) is not overridden in concrete class. – Tobiesque 2 hours ago

这篇关于是什么让 pylint 认为我的课程是抽象的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆