sourcery
sourcery copied to clipboard
Allow user to specify other valid `classmethod` decorators to avoid false-positive "The first argument to instance methods should be `self`."
Issue description or question
In my case, a Pydantic @validator decorator is an implicit @classmethod, but Sourcery complains. There are perhaps other custom decorators that imply @classmethod besides the one in Pydantic. In flake8, you can specify a list of synonyms to @classmethod in the classmethod-decorators config to avoid false positives from flake8. A similar approach could be taken in Pydantic, as well.
Of course I know that "configuration creep" is a problem in itself, so if Sourcery decides not to implement this, then it should be documented as such in the documentation for the "The first argument to instance methods should be self," refactoring. If this becomes a wontfix, for posterity a workaround is to decorate with @classmethod in addition to any implicit class method decorators such as @validator from Pydantic.
By the rationale of "explicit is better than implicit", perhaps we should be double-decorating such implicit class methods. But by the rationale of "don't repeat yourself", double-decorating everywhere can be a pain.
Sourcery Version
Sourcery v0.11.2
Code editor or IDE name and version
VSCode v1.66.2
OS name and version
Windows 10
Despite being related to #220, I figured this was different enough to warrant its own issue.
Hi @blakeNaccarato, thanks for opening this issue!
You are completely right, we definitely need to rethink the way this refactoring works, moving towards a more general solution. I've added it to our internal pipeline.
This issue has been addressed in our next release - the rule will not be suggested where any decorator exists to avoid false positives.
Looks like this is fixed per the release notes for 1.0.2, so I'll close it now. Thanks!