标签: pylint

Python 复合模式异常处理和 pylint

我以这种方式实现复合模式:

1)“抽象”部分是:

class Component(object):
    """Basic Component Abstraction"""
    def __init__(self, *args, **kw):
        raise NotImplementedError("must be subclassed")

    def status(self):
        """Base Abstract method"""
        raise NotImplementedError("must be implemented")
Run Code Online (Sandbox Code Playgroud)

2)一片叶子:

class Leaf(Component):
    """Basic atomic component
    """
    def __init__(self, *args, **kw):
        self.dict = {}

    def status(self):
        """Retrieves properties
        """
        return self.dict
Run Code Online (Sandbox Code Playgroud)

问题是 pylint 当然会生成以下警告:

Leaf.__init__: __init__ method from base class 'Component' is not called
Run Code Online (Sandbox Code Playgroud)

但在我的叶子中我不能要求:

def __init__(self, *args, **kw):
    Component.__init__(self, *args, **kw)
    self.dict = {}
Run Code Online (Sandbox Code Playgroud)

没有引发异常。

我必须忽略 pylint 警告还是存在一些错误的编码?

python pylint composite

1
推荐指数
1
解决办法
2115
查看次数

为什么酒吧在 pylint 中被列入黑名单

使用 pylint 对我的 django 项目进行 linting 时出现错误。Pylint 在 linting 我的 django 项目“C0102:黑名单名称“bar”(黑名单名称)时显示错误

我有一个名为 bar 的函数是正确的,但为什么这个名字被列入黑名单?我不知道有这个名字的内置程序。

python django pylint

1
推荐指数
1
解决办法
775
查看次数

Pylint 不理解 if/else 语句?

我有以下示例函数:

def example(inp):
    if not isinstance(inp, list):
        return 'Not list'
    else:
        return 'List'

>>> example('asdf')
'Not list'
>>> example(['asdf',])
'List'
Run Code Online (Sandbox Code Playgroud)

pylint抱怨说:

no-else-return:“return”后不必要的“else”

为什么它会提出这个看起来很愚蠢的警告?

python pylint python-3.x

1
推荐指数
1
解决办法
70
查看次数

PyLint 希望将变量命名为常量 [C0103]

为什么 PyLint 要求变量具有 UPPER_CASE 命名,就好像它是常量一样?

"""Stack reproducible example."""

some_list = ['foo', 'bar']
for i in some_list:
    counter = 3
    while counter != 0:
        print("Value of 'counter': " + str(counter))
        counter -= 1
Run Code Online (Sandbox Code Playgroud)

这给出了以下 linting 错误:

# C0103: Constant name "counter" doesn't conform to UPPER_CASE naming style (invalid-name)
Run Code Online (Sandbox Code Playgroud)

然而,与阿伏加德罗的常数、圆周率或真空中的声速不同, counter变化的值肯定必须使其成为“变量”?

我已阅读有关C0103 的页面,但我显然不明白某些内容。

for 循环是否被视为一次性函数,从而改变了约定,例如在这个问题中?

python pylint

1
推荐指数
1
解决办法
1704
查看次数

Pylint R1732(“考虑使用‘with’”)作为一句台词:这真的是个好建议吗?

在诸如

r = open(path, encoding="utf-8").read()
Run Code Online (Sandbox Code Playgroud)

此处为实际行),

Pylint 2.14.5 提供以下建议:

submodules-dedup.py:71:32: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
Run Code Online (Sandbox Code Playgroud)

如果我理解正确的话,建议将其更改为

with open(path, encoding="utf-8") as f:
    r = f.read()
Run Code Online (Sandbox Code Playgroud)

但这真的更好吗?

就我个人而言,我认为它没有任何可读性,至于其他问题,由于引用计数的工作原理,文件不会同时关闭吗?

python static-analysis pylint with-statement

1
推荐指数
1
解决办法
978
查看次数

我在哪里可以查看 pylint 的所有规则和最佳实践?

检查pylint规则的来源?我正在使用 pylint ,但我需要文档来检查所有 pylint 规则。

pylint python-3.x

0
推荐指数
1
解决办法
1408
查看次数

-1
推荐指数
1
解决办法
3544
查看次数