Pylint invalid constant name

前端 未结 3 1272
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:20

    When checking names, Pylint differentiates between constants, variables, classes etc. Any name that is not inside a function/class will be considered a constant, anything else is a variable.

    See http://docs.pylint.org/features.html#basic-checker

    variable-rgx:
    [a-z_][a-z0-9_]{2,30}$

    const-rgx:
    (([A-Z_][A-Z0-9_]*)|(__.*__))$

    Because you're in a function, MIN_SOIL_PARTICLE_DENS is (according to pylint) supposed to be a variable, pylint however treats it as a constant and therefore complains.

    This means you can't have any uppercase names inside functions without pylint complaining.


    If you ask me, using uppercase inside functions is fine; not all constants are necessarily defined globally.

提交回复
热议问题