Skip to content

Commit

Permalink
Fix FN for invalid-name for type-annotated module constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jul 7, 2024
1 parent 52955ba commit f33262e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9770.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Check module-level constants with type annotations for ``invalid-name``.

Closes #9770
6 changes: 3 additions & 3 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ def visit_assignname( # pylint: disable=too-many-branches

# Check names defined in AnnAssign nodes
elif isinstance(assign_type, nodes.AnnAssign):
if utils.is_assign_name_annotated_with(node, "Final"):
self._check_name("const", node.name, node)
elif self._assigns_typealias(assign_type.annotation):
if self._assigns_typealias(assign_type.annotation):
self._check_name("typealias", node.name, node)
else:
self._check_name("const", node.name, node)

# Check names defined in function scopes
elif isinstance(frame, nodes.FunctionDef):
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/i/invalid/invalid_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
except ValueError:
time = None # [invalid-name]

bbb: int = 42 # [invalid-name]

try:
from sys import argv, executable as python
except ImportError:
Expand Down
13 changes: 7 additions & 6 deletions tests/functional/i/invalid/invalid_name.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
invalid-name:12:0:12:3::"Constant name ""aaa"" doesn't conform to UPPER_CASE naming style":HIGH
invalid-name:16:4:16:8::"Constant name ""time"" doesn't conform to UPPER_CASE naming style":HIGH
invalid-name:36:0:36:5:A:"Function name ""A"" doesn't conform to snake_case naming style":HIGH
invalid-name:50:4:50:13::"Constant name ""Foocapfor"" doesn't conform to UPPER_CASE naming style":HIGH
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
invalid-name:74:23:74:29:FooBar.__init__:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
invalid-name:80:8:80:14:FooBar.func1:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
invalid-name:100:8:100:15:FooBar.test_disable_mixed:"Argument name ""fooBar2"" doesn't conform to snake_case naming style":HIGH
invalid-name:18:0:18:3::"Constant name ""bbb"" doesn't conform to UPPER_CASE naming style":HIGH
invalid-name:38:0:38:5:A:"Function name ""A"" doesn't conform to snake_case naming style":HIGH
invalid-name:52:4:52:13::"Constant name ""Foocapfor"" doesn't conform to UPPER_CASE naming style":HIGH
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
invalid-name:76:23:76:29:FooBar.__init__:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
invalid-name:82:8:82:14:FooBar.func1:"Argument name ""fooBar"" doesn't conform to snake_case naming style":HIGH
invalid-name:102:8:102:15:FooBar.test_disable_mixed:"Argument name ""fooBar2"" doesn't conform to snake_case naming style":HIGH

0 comments on commit f33262e

Please sign in to comment.