pep8-naming icon indicating copy to clipboard operation
pep8-naming copied to clipboard

Classmethod decorators may not be standalone

Open jace opened this issue 4 years ago • 3 comments

I have a related problem to #38: SQLAlchemy has a hybrid_property module that allows declaring a property distinctly for the instance and the class:

class MyClass(...):
    @hybrid_property
    def my_property(self):
        ...

    @my_property.setter
    def my_property(self, value):
        ...

    @my_property.expression
    def my_property(cls):  # NOQA: N805
        ...

    @my_property.comparator
    def my_property(cls):  # NOQA: N805
        ...

Since expression and comparator are contained within the property, I can't simply use --classmethod-decorators=expression,comparator to turn off warnings for them. I need to explicitly use NOQA: N805 each time.

It'll be nice if classmethod-decorators accepted a pattern instead of a symbol name.

jace avatar Jul 10 '19 21:07 jace

This is similar to #82, which proposes something similar (glob support) to ignore-names.

jparise avatar Jan 02 '20 18:01 jparise

This would be really useful to have. Right now I have no choice but disabling N805 because honestly, adding noqa for almost 50 sqlalchemy hybrid property expression functions would be way too much noise...

How quickly would this make it into a release if I were to submit a PR for it?

ThiefMaster avatar Mar 29 '23 22:03 ThiefMaster

So while looking into how to implement this I realized that only the last segment in case of dotted decorator name is used. So this works fine in an application that uses SQLAlchemy hybrids:

classmethod_decorators =
    classmethod
    declared_attr
    expression
    comparator

ThiefMaster avatar Mar 31 '23 12:03 ThiefMaster