Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trouble getting pylint to find inherited methods in pylons/SA models

I have a Pylons app that I'm using SqlAlchemy declarative models for. In order to make the code a bit cleaner I add a .query onto the SA Base and inherit all my models from that.

So in my app.model.meta I have

Base = declarative_base()
metadata = Base.metadata
Session = scoped_session(sessionmaker())

Base.query = Session.query_property(Query)

I think inherit this into app.model.mymodel and declare it as a child of meta.Base. This lets me write my queries as

mymodel.query.filter(mymodel.id == 3).all()

The trouble is that pylint is not seeing .query as a valid attribute of my models.

E:102:JobCounter.reset_count: Class 'JobCounter' has no 'query' member

Obviously this error is all over the place since it occurs on any model doing any query. I don't want to just skip the error because it might point out something down the road on non-orm classes, but I must be missing something for pylint to accept this.

Any hints?

like image 830
Rick Avatar asked Oct 31 '10 03:10

Rick


1 Answers

Best I could find for this is to pass pylint a list of classes to ignore this check on. It'll still do other checks for these classes, you'll just have to maintain a list of these somewhere:

pylint --ignored-classes=MyModel1,MyModel2 myfile.py

I know it's not ideal, but there's something about the way that sqlalchemy sets up the models that confuses pylint. At least with this you still get the check for non-orm classes.

like image 55
Adam Wagner Avatar answered Nov 09 '22 06:11

Adam Wagner