Message
Invalid %s name "%s"
Invalid constant name "newline"
Invalid variable name "MyVar"
Invalid class name "myClass"
...
Description
Verbose name: invalid-name
Used when a name doesn't doesn't fit the naming convention associated to its type (constant, variable, class…).
This message belongs to the basic checker.
Explanation
PyLint raises this message when an object has a name that doesn't fit the naming convention associated to its object type.
The naming convention is defined with a regular expression, and the naming convention is satisfied if the name matches the regular expression. The regular expression syntax is the normal Python regular expression syntax, as used in Python raw strings (e.g. r"abc").
Options can be used to override the default regular expression associated to each type. The table below lists the types, their associated options, and their default regular expressions.
Type | Option | Default regular expression |
---|---|---|
Argument | argument-rgx | [a-z_][a-z0-9_]{2,30}$ |
Attribute | attr-rgx | [a-z_][a-z0-9_]{2,30}$ |
Class | class-rgx | [A-Z_][a-zA-Z0-9]+$ |
Constant | const-rgx | (([A-Z_][A-Z0-9_]*)|(__.*__))$ |
Function | function-rgx | [a-z_][a-z0-9_]{2,30}$ |
Method | method-rgx | [a-z_][a-z0-9_]{2,30}$ |
Module | module-rgx | (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ |
Variable | variable-rgx | [a-z_][a-z0-9_]{2,30}$ |
Variable, inline1 | inlinevar-rgx | [A-Za-z_][A-Za-z0-9_]*$ |
In addition, the following options are related to naming conventions:
- The good-names option defines names that are always accepted, even if the regular expression associated to its type does not match.
- The bad-names option defines names that are always rejected (see C0102), even if the regular expression associated to its type matches.
Options that are not really related to naming conventions, but to names:
- The bad-functions option defines the names of built-in functions that should not be used (see W0141).
Being new to pylint, I have a lot to learn.
Please can someone with more experience give me some guidance?
I have a line of code which sets a string variable from a call to a class method.
The string is not intended to be modified within the scope of the function.
PRIKEY = p_database.get_key()
I made it upper case because it won't be changed.
C0103 says it doesn't comply with snake_case.
Do I really have to make it PRI_KEY to be snaky enough?
In Vscode I had the case that this was highlighted for the a perforce connection instance named p4
As this is all over the place and not questioned by anybody I was looking up ways to add this to the accepted names.
In the Pylint Args one can add a line like:
Voilà!