Definition of constant

There are a few constants in the code. In all cases that I’m aware of (I make no claim to be complete) those constants are defined right before they are used, and they are used two or three times. I was wondering whether those constant definitions should stay where they are.

I could think of having one place where all kind of constants are gathered. This would be a wild bunch of stuff, but only one place to look for constants. I could also think of defining them on the module level instead of (nested) function level. This way they would stay where they logically belong, but still be defined in a definite spot (at the beginning of a module). I could think of demoting them to plain variables, as they are only used within a few lines after their definition. And lastly, I can also think of ignoring this PyCharm warning complaining about variables with non-lowercase names in functions :wink:

This is a pretty minor problem, but I just came across those warnings and didn’t know how to address them separate from decorating them with a TODO.

1 Like

IDEs like PyCharm issue warnings for various reasons (not always important, in my opinion), but we welcome efforts to improve the codebase.

I don’t think there’s a particular advantage in having all constants defined in a central module, not always anyway, it depends on the constant.

I’d say these reasons are good reasons for placing constants in a central module:

  • Makes code easier to read
  • Makes code easier to maintain

Not so good reasons:

  • Making the IDE / linter happy