Pylint找不到SQLAlchemy查询成员 [英] Pylint can't find SQLAlchemy query member
问题描述
我有一个使用Flask-SQLAlchemy(v2.0)的Flask(v0.10.1)应用程序,并且我正在尝试配置Pylint进行检查.使用Python 3.4.2.运行.
I have a Flask (v0.10.1) application using Flask-SQLAlchemy (v2.0) and I'm trying to configure Pylint to check it. Running with Python 3.4.2.
第一个错误是:
Instance of 'SQLAlchemy' has no 'Table' member (no-member)
我修复了这个问题,而忽略了对SQLAlchemy成员属性的检查:
And I fixed this one ignoring the check for member attributes on SQLAlchemy:
ignored-classes=SQLAlchemy
但是我在实体上的查询成员遇到了问题:
But I'm having a problem with the query member on entities:
Class 'UserToken' has no 'query' member (no-member)
有什么方法可以解决此问题,而不必在每次查询调用时都忽略无成员错误?
Is there any way to fix this issue without having to ignore no-member errors on every query call?
烧瓶引导程序:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
app = Flask(__name__)
db.init_app(app)
app.run()
UserToken实体:
UserToken entity:
from app import db
class UserToken(db.Model):
user_token_id = db.Column(db.Integer, primary_key=True, index=True)
token_auth = db.Column(db.String(64), unique=True, nullable=False, index=True)
控制器:
from entities import UserToken
token = UserToken.query.filter(
UserToken.token_auth == token_hash,
).first()
推荐答案
解决方案
pip install pylint-flask
pip install pylint-flask-sqlalchemy
加载已安装的插件.
例如,如果您使用VS代码,请按如下方式编辑settings.json文件:
For example, if you use VS code, please edit settings.json file as follows:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
如果还有其他警告,请在pylintrc
文件的generated-members
中定义其余成员.
If having other warnings, define remaining members in generated-members
in pylintrc
file.
这篇关于Pylint找不到SQLAlchemy查询成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!