0

I have a pydantic.validator in my code:

class Foo(pydantic.BaseModel):
    ...

    @pydantic.validator('some_arg')
    def validate_arg(cls, value):
        ...

However, pylint complains:

E0213: Method should have "self" as first argument (no-self-argument)

Is there a way, perhaps by adding either a comment to the code or an option to pyproject.toml, to make pylint understand that pydantic.validator makes the method a class method?

I've seen people recommend adding the classmethod decorator:

    @pydantic.validator('some_arg')
    @classmethod
    def validate_arg(cls, value):
        ...

While this does make the error go away, I'm wary of satisfying a linter by changing the actual code. That is, I don't know if chaining pydantic.validator and classmethod will break something in pydantic's logic.

To be clear, I don't want to have pylint completely ignore E0213 but just when I use pydantic.validator.

Daniel Walker
  • 5,220
  • 3
  • 18
  • 39

0 Answers0