When I initialize an empty list to be populated dynamically later in my code, pylint sees it as an "invalid constant name" even if it is modified repeatedly throughout the code. For example:
myvar = [] # pylint flags this as C0103: invalid constant name "myvar"
myvar.append('x')
It feels weird to need to disable C0103 for these situations. Any chance this behavior could be changed to not consider an empty list a constant if it's modified later?
The error doesn't have to do with the fact that the list is modified later on in the code, but with the fact that you are defining it at the module level, if I presume correctly. Pylint considers every variable that's defined at the module level as "constants" and it expects for them to be named with uppercase letters. There are multiple ways you can avoid this: you can customize the const-rgx option with a particular regex, as in --const-rgx=[a-z]+, you can add that particular name in the list of good names, with --good-names=myvar.
You can also see the current naming hints, by providing the --include-naming-hints=y flag to pylint.
Thanks very much for the quick and detailed answer. I get it now ... and that explains why I haven't run into this before, it's because this is indeed being defined at the module level. I'll use one of the workarounds you suggested. Pylint rocks!
Thank you!
Thanks for the answer @PCManticore !
Thx for your answer @PCManticore !
Most helpful comment
The error doesn't have to do with the fact that the list is modified later on in the code, but with the fact that you are defining it at the module level, if I presume correctly. Pylint considers every variable that's defined at the module level as "constants" and it expects for them to be named with uppercase letters. There are multiple ways you can avoid this: you can customize the const-rgx option with a particular regex, as in
--const-rgx=[a-z]+, you can add that particular name in the list of good names, with--good-names=myvar.You can also see the current naming hints, by providing the
--include-naming-hints=yflag to pylint.