pylint-flask
pylint-flask is a Pylint plugin designed to improve static code analysis for Flask applications. It helps Pylint correctly interpret Flask-specific patterns, particularly addressing issues related to the `flask.ext` import style (which has since been deprecated in Flask itself) and other dynamic attributes in Flask extensions. The current version is 0.6, released in January 2019, indicating a maintenance phase with infrequent updates.
Common errors
-
E: No name 'ext' in module 'flask' (no-name-in-module)
cause Pylint, without the plugin, does not understand the historical `flask.ext` import mechanism used for Flask extensions.fixEnsure `pylint-flask` is installed and loaded when running Pylint: `pylint --load-plugins pylint_flask your_module.py`. For modern Flask, prefer direct imports like `from flask_wtf import CSRFProtect`. -
E: No module named flask.ext.wtf
cause Similar to `no-name-in-module`, Pylint's import resolver fails to find modules imported via the `flask.ext` namespace.fixLoad the `pylint-flask` plugin: `pylint --load-plugins pylint_flask your_module.py`. If using Flask 2.0+, update your code to use direct imports (e.g., `import flask_wtf` or `from flask_wtf import ...`). -
E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
cause Pylint cannot statically determine members added dynamically by extensions like Flask-SQLAlchemy to base objects.fixInstall and load `pylint-flask-sqlalchemy` alongside `pylint-flask` (`pip install pylint-flask-sqlalchemy` then `pylint --load-plugins pylint_flask,pylint_flask_sqlalchemy your_module.py`). Alternatively, you can add `--generated-members=Column,Integer,String` (etc.) to your Pylint configuration or disable `no-member` for specific lines/modules.
Warnings
- breaking The `flask.ext` import pattern, which `pylint-flask` was primarily designed to address, was officially deprecated and removed in Flask 2.0. If you are using Flask 2.0 or newer, you should be using direct imports for extensions (e.g., `from flask_wtf import ...`). `pylint-flask`'s core functionality for `flask.ext` may be less relevant or even cause unexpected linting behavior with modern Flask applications.
- gotcha While `pylint-flask` helps with generic Flask patterns, it may not fully resolve `E1101: no-member` errors for specific Flask extensions like Flask-SQLAlchemy or Flask-Migrate where attributes are dynamically added to objects. You might still encounter false positives for `db.Column`, `db.Integer`, etc.
- gotcha Pylint might report `W0611: Unused import <module_name>` even when an import is indirectly used, for example, by a decorator or if `pylint-flask` transforms an import, but the original reference isn't explicitly used elsewhere in the file.
Install
-
pip install pylint-flask
Imports
- pylint_flask
from pylint_flask import ...
pylint --load-plugins pylint_flask your_module.py
Quickstart
# my_flask_app.py
from flask import Flask
from flask_wtf import CSRFProtect # Example: direct import for Flask-WTF
app = Flask(__name__)
app.config['SECRET_KEY'] = 'a-very-secret-key'
csrf = CSRFProtect(app)
@app.route('/')
def index():
return 'Hello, Flask!'
# To run pylint with the plugin:
# pylint --load-plugins pylint_flask my_flask_app.py