pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.24k stars 1.12k forks source link

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

Open jacobtylerwalls opened 2 months ago

jacobtylerwalls commented 2 months ago

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

mbyrnepr2 commented 2 months ago

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.

jacobtylerwalls commented 2 months ago

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 commented 2 months ago

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.

Pierre-Sassoulas commented 2 months ago

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 ?).

jacobtylerwalls commented 2 months ago

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 commented 2 months ago

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

DanielNoord commented 2 months ago

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