C0103 - PyLint Messages - Wikidot

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_]*$
1. Used as part of list comprehensions and generators.

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).
Show Comments Hide All Comments Unfold All Fold All Fold what about simple string variables not intended to be changed Douglas GoodallDouglas Goodall 07 Nov 2018 15:04

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?

Options Unfold what about simple string variables not intended to be changed by Douglas GoodallDouglas Goodall, 07 Nov 2018 15:04 Fold If you want to add to the good-names ewerybodyewerybody 16 Apr 2020 11:30

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:

--good-names=i,j,p4 Voilà! Options Unfold If you want to add to the good-names by ewerybodyewerybody, 16 Apr 2020 11:30 Add a New Comment Permanent Link Edit Delete

Từ khóa » C0103