pylint - pylint 不能检测到未解析的属性引用吗?
问题描述
我们多次认为 pylint 没有捕获一个简单的未解决的属性引用错误。
我查看了 pylint 代码,但无法立即找到它。像 PyCharm 这样的 IDE 可以检测到,所以在 pylint 中一定可以检测到。我们将 pylint 用作 CI 作业,并希望能够在合并代码之前检测到这一点。
我需要启用哪些 pylint 设置才能捕获如下错误?
class A():
df test_a(self):
print("A")
a = A()
a.test_b() # this should be caught by pylint.
解决方案
你用的是什么版本的pylint?pylint 2.8.2 和 mypy 0.812 都检测到这个问题。
与b.py
:
class A():
def test_a(self):
print("A")
a = A()
a.test_b() # this should be caught by pylint.
pylint b.py
:
************* Module b
b.py:2:4: R0201: Method could be a function (no-self-use)
b.py:6:0: E1101: Instance of 'A' has no 'test_b' member; maybe 'test_a'? (no-member)
------------------------------------
Your code has been rated at -2.00/10
mypy b.py
:
b.py:6: error: "A" has no attribute "test_b"; maybe "test_a"?
Found 1 error in 1 file (checked 1 source file)