I'm confused about the error(s) in this photo:
I don't know how to fix them. My program is a Python-Flask web frame. When I use Visual Studio Code to debug my program, Pylint shows these errors. I know this problem doesn't matter, but it makes me annoyed. How can I fix it?
# -*- coding: utf-8 -*- import sys from flask import Flask from flask_bootstrap import Bootstrap from flask_moment import Moment #from flask_wtf import Form #from wtforms import StringField, SubmitField #from wtforms.validators import Required from flask_sqlalchemy import SQLAlchemy reload(sys) sys.setdefaultencoding('utf-8') app = Flask(__name__) app.config['SECRET_KEY'] = 'hard to guess string' app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost:3306/test?' app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True bootstrap = Bootstrap(app) moment = Moment(app) db = SQLAlchemy(app) if __name__ == '__main__': db.create_all() app.run()
Pylint has a standard format to its output. When there is a syntax error, it will not show a code rating. Depending on your version of Pylint, you may or may not see the first line informing you what . pylintrc configuration file you're using. This allows you to verify that you're using the one you intended to.
OUTPUT Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are 5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) ...
As explained by Kundor, PEP 8 states that:
Constants are usually defined on a module level and written in all capital letters with underscores separating words.
The point is that "constants" in Python don't really exist. Pylint, as per PEP 8, expects module level variables to be "constants."
That being said you've several options:
you don't want this "constant" thing, then change Pylint's const-rgx
regular expression to be the same as e.g. variable-rgx
,
you may deactivate those warnings for this file, or even locally in the file, using # pylint: disable=invalid-name
,
avoid module level variables, by wrapping them into a function.
In your case, I would go with the third option, by creating a build_app
function or something similar. That would return the application (and maybe the 'db' object as well, but you have several choices there). Then you could add a salt of the second option to get something like:
app = build_app() # pylint: disable=invalid-name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With