我以这种方式实现复合模式:
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 警告还是存在一些错误的编码?
使用 pylint 对我的 django 项目进行 linting 时出现错误。Pylint 在 linting 我的 django 项目“C0102:黑名单名称“bar”(黑名单名称)时显示错误
我有一个名为 bar 的函数是正确的,但为什么这个名字被列入黑名单?我不知道有这个名字的内置程序。
我有以下示例函数:
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”
为什么它会提出这个看起来很愚蠢的警告?
为什么 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 循环是否被视为一次性函数,从而改变了约定,例如在这个问题中?
在诸如
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)
但这真的更好吗?
就我个人而言,我认为它没有任何可读性,至于其他问题,由于引用计数的工作原理,文件不会同时关闭吗?
检查pylint规则的来源?我正在使用 pylint ,但我需要文档来检查所有 pylint 规则。
我被困在这里,不知道为什么会发生这个错误。在此处输入图片说明