gwax / pylint-sqlalchemy

pylint plugin to fix incompatibility issues with sqlalchemy
MIT License
4 stars 5 forks source link

Method should have 'self' as first argument issue with declared_attr #4

Open tgross35 opened 3 years ago

tgross35 commented 3 years ago

I've experienced this with SQLA's declared_attr decorator. I'm assuming that other "classmethod-like" decorators would also run into the same issue.

@declared_attr
def time_updated(cls):
    return Column(DateTime(255), onupdate=func.now())

Results in:

{
    "owner": "python",
    "code": "no-self-argument",
    "severity": 8,
    "message": "Method should have \"self\" as first argument",
    "source": "pylint"
}
MiltiadisKoutsokeras commented 2 years ago

This is also true when using the example Mixin from the official documentation:

@declarative_mixin
class MyMixin:

    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    __table_args__ = {'mysql_engine': 'InnoDB'}
    __mapper_args__ = {'always_refresh': True}

    id = Column(Integer, primary_key=True)

This example is marked with Method should have 'self' as first argument.