English 中文(简体)
使pylint在pylons/SA模型中查找继承方法时出现问题
原标题:trouble getting pylint to find inherited methods in pylons/SA models

我有一个Pylons应用程序,我正在使用SqlAlchemy声明性模型。为了使代码更简洁,我在SA基础上添加了一个.query,并从中继承了我的所有模型。

所以在我的app.model.meta中,我有

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

Base.query = Session.query_property(Query)

我想将其继承到app.model.mymodel中,并将其声明为meta.Base的子级

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

问题是pylint没有将.query视为我的模型的有效属性。

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

显然,这个错误无处不在,因为它发生在执行任何查询的任何模型上。我不想跳过这个错误,因为它可能会指出一些关于非orm类的问题,但我一定错过了一些东西,让pylint接受这一点。

有什么提示吗?

最佳回答

我能找到的最好的方法是向pylint传递一个类列表以忽略此检查。它仍然会对这些类进行其他检查,您只需要在某个地方维护这些类的列表:

pylint--忽略的类=MyModel1,MyModel2 myfile.py

我知道这并不理想,但sqlalchemy建立模型的方式有些让pylint感到困惑。至少这样,您仍然可以检查非orm类。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签