Skip to content

Pylint does not warn on assignment to constants #7232

@omarandlorraine

Description

@omarandlorraine

Bug description

Here is the contents of the file sglobals.py

#pylint: disable=missing-module-docstring
TheGreetingWithABadName = "Hello, World!"

Here is the output of pylint sglobals.py:

sglobals.py:2:0: C0103: Constant name "TheGreetingWithABadName" doesn't conform to UPPER_CASE naming style (invalid-name) 

Clearly the opinion is that TheGreetingWithABadName is a constant, so it must be a codesmell if we later assign to this. But pylint has nothing to say about the following file in the same directory:

#pylint: disable=missing-module-docstring
import sglobals

sglobals.TheGreetingWithABadName = "Hello, OtherWorld!"

Similarly, assigning to module-level functions and so is not caught by pylint.

Configuration

No response

Command used

pylint a.py

Pylint output

Your code has been rated at 10.00/10

Expected behavior

I would have expected a warning to the effect that assigning to module level variables is at least frowned upon

Pylint version

pylint 2.14.4
astroid 2.11.7
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110]

OS / Environment

Debian 11.4

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions