Skip to content

Some module level variables names are not checked for invalid-name. #7383

@dmail00

Description

@dmail00

Bug description

Reference: #2166 (comment)

I will pretty much just copy and paste what has already been said.

The following shows the issue with two version of pylint 2.4.4 and 3.15.0 (latest). The reason for using 2.4.4 is due to it being the last version before the change was made in 2.5.0 regarding constant names in the global scope.

The following was run with 2.4.4 and 3.15.0

FooBar = ["something"]

def foobar():
    FooBar[0] = "something else"
    FooBar.append("what ever")
    somethingElse = ""

With 2.4.4 it was at least detecting that the name in the global scope did not conform, although reporting it as a Constant

pylint --variable-naming-style=snake_case check_globals
************* Module check_globals
check_globals.py:1:0: C0114: Missing module docstring (missing-module-docstring)
check_globals.py:1:0: C0103: Constant name "FooBar" doesn't conform to UPPER_CASE naming style (invalid-name)
check_globals.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
check_globals.py:6:4: C0103: Variable name "somethingElse" doesn't conform to snake_case naming style (invalid-name)
check_globals.py:6:4: W0612: Unused variable 'somethingElse' (unused-variable)

With 3.15.0 it doesn't care.

pylint --variable-naming-style=snake_case check_globals
************* Module check_globals
check_globals.py:1:0: C0114: Missing module docstring (missing-module-docstring)
check_globals.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
check_globals.py:6:4: C0103: Variable name "somethingElse" doesn't conform to snake_case naming style (invalid-name)
check_globals.py:6:4: W0612: Unused variable 'somethingElse' (unused-variable)

It seems to be an unintended consquence that some global names are no longer checked. snake_case was specified on the command line for variables and whilst pylint may not be able to detect if it is a variable or constant it should report some error number as it does not match UPPER_CASE or snake_case.
Prior to 2.5.0 I could specify the regex for consts

"--const-rgx=(([a-z_][a-z0-9_]{2,30})|([A-Z_][A-Z0-9_]{2,30})|(__.*__))$"

Then I would patch the message in a custom reporter class and report that a global name doesn't conform to the naming standards. Since 2.5.0 the library is ignoring some module level names which have the same conventions to functions as per PEP-8.[1][2]

[1] https://peps.python.org/pep-0008/#global-variable-names
[2] https://peps.python.org/pep-0008/#function-and-variable-names

Configuration

No response

Command used

see above

Pylint output

see above

Expected behavior

C0103

Pylint version

pylint 2.5.0 -> 3.15.0

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: invalid-nameFalse Negative 🦋No message is emitted but something is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions