I use factory-boy package and pylint for static linting. For the following code the linter emits the no-self-argument
error.
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)
I don't want to hide the message completely. But instead, I'd like to tell pylint that the @factory.lazy_attribute
decorator behaves just like the @staticmethod
builtin, so the method requires one argument less. Is it possible? Is there a special setting in pylintrc that is responsible for declarations of static methods?
According to the doc:
This decorates an instance method that should take a single argument, self; the name of the method will be used as the name of the attribute to fill with the return value of the method:
That means you should name your argument self
instead of obj