pylint icon indicating copy to clipboard operation
pylint copied to clipboard

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

Open jacobtylerwalls opened this issue 1 year ago • 7 comments

Originally reported by @mbyrnepr2 in https://github.com/pylint-dev/pylint/issues/7232#issuecomment-1197868763.

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

jacobtylerwalls avatar Jul 07 '24 14:07 jacobtylerwalls

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.

mbyrnepr2 avatar Jul 07 '24 20:07 mbyrnepr2

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!

jacobtylerwalls avatar Jul 07 '24 20:07 jacobtylerwalls

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.

jacobtylerwalls avatar Jul 07 '24 20:07 jacobtylerwalls

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 https://github.com/pylint-dev/pylint/issues/3585#issuecomment-1433774348 to be implemented before merging it (it's as simple as a regex change, right ?).

Pierre-Sassoulas avatar Jul 07 '24 20:07 Pierre-Sassoulas

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.

jacobtylerwalls avatar Jul 07 '24 22:07 jacobtylerwalls

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

jacobtylerwalls avatar Jul 08 '24 13:07 jacobtylerwalls

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

DanielNoord avatar Jul 08 '24 13:07 DanielNoord