我使用factory-boy包和pylint进行静态linting。对于以下代码,linter发出no-self-argument
错误。你知道吗
import factory
from factory import Factory, Faker
class MyTestFactory(Factory):
class Meta:
model = dict
a = Faker("pyint")
b = Faker("pyint")
@factory.lazy_attribute
def a_and_b(obj): # <-- no-self-argument here
return obj.a + obj.b
if __name__ == "__main__":
O1 = MyTestFactory.build()
print(f"dbg: {O1=}")
example2.py:12:4: E0213: Method should have "self" as first argument (no-self-argument)
我不想把信息完全隐藏起来。但是,我想告诉pylint,@factory.lazy_attribute
装饰器的行为就像@staticmethod
内置的一样,因此该方法只需要少一个参数。有可能吗?pylintrc中是否有负责静态方法声明的特殊设置?你知道吗
根据doc:
这意味着您应该将参数命名为
self
,而不是obj
相关问题 更多 >
编程相关推荐