Constant variable imported as non-constant

I’m new to python using pycharm as my IDE to work with Gramps. Pycharm is giving me lots of warnings about the code using PEB 8. Most of it I can understand and have made changes to the code to clean it up so no warnings are showing. But one has me stumped and I can’t find anything on the web to fix it. It’s the Constant variable imported as non-constant warning being generated by the code

from gramps.gen.const import GRAMPS_LOCALE as glocale

I know I can ignore it but I would like to fix it if I can. Must be my OCD causing me to dwell on it.

This occurs because GRAMPS_LOCALE (being all caps) is considered a constant. It isn’t, since it refers to an class.

I think this is a side effect of Gramps history; much of it was written before PEP8 was even a thing. I would just ignore this.

In addition there is no true constant symbol in Python because the notion doesn’t exist. The “constant semantics” is purely a convention and nothing forbids you from assigning a new value to a “constant” symbol (written in uppercase). Only ancillary tools will detect the violation of the convention. The Python interpreter will blindly execute the change of value.

I just added

gramps_locale = GRAMPS_LOCALE to const.py

and as I’m cleaning up files, I’m changing GRAMPS_LOCALE to lower case as I go through files. I know I can do a find and replace but I’m testing to see if I break anything before I proceed. I was taught an error or warning message should be fixed and not ignored so I’m doing that as I go along. Being new to Python, still trying to learn why some things are done the way they are in Gramps.

I don’t agree with that. I think you are loosing your time.

PEP8 says:

Constants

Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL .

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.