Error message “python-pylint ‘C0103:Invalid constant name”

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

Leave a Comment