Pylint can't find SQLAlchemy query member

前端 未结 13 1445
予麋鹿
予麋鹿 2021-01-30 08:25

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.

First error was:



        
13条回答
  •  面向向阳花
    2021-01-30 08:54

    Warning: Do not just --load-plugins pylint-flask

    • By doing this (using dashes instead of underscores) you will just disable pylint altogether! This is because the --load-plugins needs the name of the python package to be imported. You can check this on command line (will get ImportError) if you do so. Pylinting in VS Code is nastier since you will not get any visible errors. Instead, you will have zero linting errors even if your code would have some linting problems.

    pylint-flask will not work

    pylint-flask is a good plugin, but it is not even meant to tackle this problem! You can see the source code for yourself. There is no mentions about Flask-SQLAlchemy; it is only designed to fix issues (false positives) with Flask.

    pylint-flask-sqlalchemy

    The pylint-flask-sqlalchemy was created to fix the pylint false positives with Flask-SQLAlchemy. After installing with

    pip install pylint-flask-sqlalchemy
    

    one should add it with1

    # NOT: "pylint-flask-sqlalchemy"
    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
    

    1Applies directly only for VS Code. With other IDEs or command line, use the same arguments in the same order.

    pylint-flask with pylint-flask-sqlalchemy

    If used together, for some reason

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
    

    will not work but

    "python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
    

    does. So, presumably, the pylint-flask must be loaded after pylint-flask-sqlalchemy.

提交回复
热议问题