C0103 invalid-name

Message

'%s name "%s" doesn\'t conform to %s'

Description

Used when the name doesn’t conform to naming rules associated to its type (constant, variable, class…).

Pylint by default uses the convention for names from PEP 8.

Examples

In the following example all the conventions are violated.

some_const = 1

def functionName(ARG_NAME):
    VARIABLE_NAME = 1

class cls_name:
    def METHOD_NAME(self):
        pass
1:0: C0103: Constant name "some_const" doesn't conform to UPPER_CASE naming style
3:0: C0103: Function name "functionName" doesn't conform to snake_case naming style
3:0: C0103: Argument name "ARG_NAME" doesn't conform to snake_case naming style
4:4: C0103: Variable name "VARIABLE_NAME" doesn't conform to snake_case naming style
6:0: C0103: Class name "cls_name" doesn't conform to PascalCase naming style
7:4: C0103: Method name "METHOD_NAME" doesn't conform to snake_case naming style

Here is what it should look like:

SOME_CONST = 1

def function_name(arg_name):
    variable_name = 1

class ClsName:
    def method_name(self):
        pass
No issues found.

Why bother?

Names are one of the most important aspects of software maintenance. With good, consistent names code becomes more understandable. It makes sense to have a convention on how to use different naming styles because it allows you to have a quick idea what kind of object a name referers to. E.g. when you read MyFancyView you can assume you are looking at a class.

Running Pylint locally? In your CI?

There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.