Pylint invalid constant name

前端 未结 3 1265
Happy的楠姐
Happy的楠姐 2021-01-31 06:39

I\'m receiving a Pylint error regarding my constant: MIN_SOIL_PARTICLE_DENS (invalid name). Any ideas why this constant is wrong? Here\'s my full function:

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 07:24

    I found this behavior annoying, but there's a way to configure pylint to avoid this!

    Merge the following ini-style declaration into your .pylintrc file:

    [BASIC]
    variable-rgx=((([a-z_][a-z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$)|([A-Z_][A-Z0-9_]+$)
    

    I built this regex by taking

    • the default snake_case regex taken from pylint's source at this line,

    • the default CONST_VAR regex taken from pylint's source at this line

    and joining them by | and some parentheses.

    Theoretically, you could also just take .*, but this would allow even invalid names like mixed_CASE.

提交回复
热议问题