Skip to content

Commit 8492003

Browse files
Fix FN for invalid-name for type-annotated module constants
1 parent 52955ba commit 8492003

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Check module-level constants with type annotations for ``invalid-name``.
2+
Remember to adjust ``const-naming-style`` or ``const-rgx`` to your liking.
3+
4+
Closes #9770

pylint/checkers/base/name_checker/checker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ def visit_assignname( # pylint: disable=too-many-branches
473473

474474
# Check names defined in AnnAssign nodes
475475
elif isinstance(assign_type, nodes.AnnAssign):
476-
if utils.is_assign_name_annotated_with(node, "Final"):
477-
self._check_name("const", node.name, node)
478-
elif self._assigns_typealias(assign_type.annotation):
476+
if self._assigns_typealias(assign_type.annotation):
479477
self._check_name("typealias", node.name, node)
478+
else:
479+
self._check_name("const", node.name, node)
480480

481481
# Check names defined in function scopes
482482
elif isinstance(frame, nodes.FunctionDef):

tests/functional/i/invalid/invalid_name.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
except ValueError:
1616
time = None # [invalid-name]
1717

18+
bbb: int = 42 # [invalid-name]
19+
1820
try:
1921
from sys import argv, executable as python
2022
except ImportError:
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
invalid-name:12:0:12:3::"Constant name ""aaa"" doesn't conform to UPPER_CASE naming style":HIGH
22
invalid-name:16:4:16:8::"Constant name ""time"" doesn't conform to UPPER_CASE naming style":HIGH
3-
invalid-name:36:0:36:5:A:"Function name ""A"" doesn't conform to snake_case naming style":HIGH
4-
invalid-name:50:4:50:13::"Constant name ""Foocapfor"" doesn't conform to UPPER_CASE naming style":HIGH
5-
invalid-name:66:0:66:68:a_very_very_very_long_function_name_WithCamelCase_to_make_it_sad:"Function name ""a_very_very_very_long_function_name_WithCamelCase_to_make_it_sad"" doesn't conform to snake_case naming style":HIGH
6-
invalid-name:74:23:74:29:FooBar.__init__:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
7-
invalid-name:80:8:80:14:FooBar.func1:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
8-
invalid-name:100:8:100:15:FooBar.test_disable_mixed:"Argument name ""fooBar2"" doesn't conform to snake_case naming style":HIGH
3+
invalid-name:18:0:18:3::"Constant name ""bbb"" doesn't conform to UPPER_CASE naming style":HIGH
4+
invalid-name:38:0:38:5:A:"Function name ""A"" doesn't conform to snake_case naming style":HIGH
5+
invalid-name:52:4:52:13::"Constant name ""Foocapfor"" doesn't conform to UPPER_CASE naming style":HIGH
6+
invalid-name:68:0:68:68:a_very_very_very_long_function_name_WithCamelCase_to_make_it_sad:"Function name ""a_very_very_very_long_function_name_WithCamelCase_to_make_it_sad"" doesn't conform to snake_case naming style":HIGH
7+
invalid-name:76:23:76:29:FooBar.__init__:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
8+
invalid-name:82:8:82:14:FooBar.func1:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
9+
invalid-name:102:8:102:15:FooBar.test_disable_mixed:"Argument name ""fooBar2"" doesn't conform to snake_case naming style":HIGH

0 commit comments

Comments
 (0)