How can I modify my pylintrc so that a given decorator is interpreted as a classmethod.
pydantic defines a validator decorator to allow for attribute validation of model classes and operates as a class method. pylint throws a
E0213: Method 'has_risk_assigned' should have "self" as first argument (no-self-argument)
for a validator method declared as:
from pydantic import BaseModel, validator
class RiskyRecord(BaseModel):
# ... attributes ...
@validator('risk')
def has_risk_assigned(cls, v):
# ... make sure that risk is properly assigned ...
How can I configure my pylintrc such that it views this decorator as defining a class (instead of instance) method?
Note: I want a solution in terms of pylintrc since there are multiple classes in this module that each use multiple validators; managing this warning in one place is more desirable.
I only see two classmethod related features in my current pylintrc; both only relate to the valid name(s) for the first argument.
Chepner said it correctly, in the comments; a plugin is necessary for
Pylintto understand thatpydantic.validatorreturns a class method.Such a plugin exists in the form of pylint-pydantic and it works to prevent the
no-self-argumentmessage from being emitted when thepydantic.validatordecorator is used.It can be added to a
pylintrclike so:Alternatively, using
pyproject.toml:For further reading about Pylint plugins, there is a short list available available in the Pylint documentation.