pylint-dev/pylint

Annotated module level constant not checked for `invalid-name`

Opened this issue ยท 7 comments

Originally reported by @mbyrnepr2 in #7232 (comment).

Bug description

"""should raise invalid-name"""
my_var: int = 1

Configuration

No response

Command used

pylint a.py

Pylint output

% pylint x.py

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)

Expected behavior

invalid-name

Pylint version

pylint 3.3.0-dev0
astroid 3.3.0-dev0
Python 3.13.0b3

OS / Environment

No response

Additional dependencies

No response

I may have gotten that all wrong.
If the snake-cased module-level name is annotated with something other then Final, then perhaps it is fair to say it is not intended to be a constant and, so, Pylint should not expect that to be uppercase.

You did identify a real issue -- annotated statements at the module level are completely escaping any sort of checking for invalid-name -- that can't be right!

We can discuss what to do in finer-grained detail for these cases in #3585, but for now, suggest to just make my_var: int do the same check as my_var.

I agree it's a bug but it's going to create a lot of new messages / spam for a patch (or even a minor) version. I think we should wait for #3585 (comment) to be implemented before merging it (it's as simple as a regex change, right ?).

Not a regex but something more like a refactor to let the invalid name check do "as-if" checks so a name can be checked twice against two regexes.

But yeah, happy to hold this until somebody works on the other one.

Hm, if the other change is waiting for 4.0 are we willing to let this wait that long also?

I'm fine with waiting. Bit annoying for users to introduce behaviour that gets replaced a couple of versions later again.