C0103

Message

Invalid %s name "%s"

Invalid constant name "newline"
Invalid variable name "MyVar"
Invalid class name "myClass"
...

Description

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:

  1. The good-names option defines names that are always accepted, even if the regular expression associated to its type does not match.
  2. 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:

  1. The bad-functions option defines the names of built-in functions that should not be used (see W0141).

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License