Skip to content

Commit f35bb24

Browse files
committed
Apply const-naming-style to module const annotated with Final
1 parent 44a3aa2 commit f35bb24

File tree

7 files changed

+16
-0
lines changed

7 files changed

+16
-0
lines changed

ChangeLog

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Release date: Undefined
99
..
1010
Put new features here and also in 'doc/whatsnew/2.8.rst'
1111

12+
* Apply ``const-naming-style`` to module constants annotated with
13+
``typing.Final``
14+
1215

1316
What's New in Pylint 2.7.5?
1417
===========================

pylint/checkers/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,10 @@ def visit_assignname(self, node):
19831983
self._check_name("const", node.name, node)
19841984
elif isinstance(assign_type, astroid.ExceptHandler):
19851985
self._check_name("variable", node.name, node)
1986+
elif isinstance(
1987+
assign_type, astroid.AnnAssign
1988+
) and utils.is_assign_name_annotated_with(node, "Final"):
1989+
self._check_name("const", node.name, node)
19861990
elif isinstance(frame, astroid.FunctionDef):
19871991
# global introduced variable aren't in the function locals
19881992
if node.name in frame and node.name not in frame.argnames():

tests/functional/n/name/name_final.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ class Foo:
1111
CLASS_CONST3: typing.Final
1212
variable2: typing.Final[int] # [invalid-name]
1313
CLASS_CONST4: Final[typing.ClassVar[str]] = "valid"
14+
15+
MODULE_CONST: Final = 1
16+
module_var: typing.Final[str] = "const" # [invalid-name]
+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
invalid-name:10:4:Foo:"Class constant name ""variable"" doesn't conform to UPPER_CASE naming style"
22
invalid-name:12:4:Foo:"Class constant name ""variable2"" doesn't conform to UPPER_CASE naming style"
3+
invalid-name:16:0::"Constant name ""module_var"" doesn't conform to UPPER_CASE naming style"

tests/functional/n/name/name_final_snake_case.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ class Foo:
1111
CLASS_CONST3: typing.Final # [invalid-name]
1212
variable2: typing.Final[int]
1313
CLASS_CONST4: Final[typing.ClassVar[str]] = "invalid name" # [invalid-name]
14+
15+
MODULE_CONST: Final = 1 # [invalid-name]
16+
module_var: typing.Final[str] = "const"

tests/functional/n/name/name_final_snake_case.rc

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ min_pyver=3.8
33

44
[BASIC]
55
class-const-naming-style=snake_case
6+
const-naming-style=snake_case

tests/functional/n/name/name_final_snake_case.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ invalid-name:8:4:Foo:"Class constant name ""CLASS_CONST"" doesn't conform to sna
22
invalid-name:9:4:Foo:"Class constant name ""CLASS_CONST2"" doesn't conform to snake_case naming style"
33
invalid-name:11:4:Foo:"Class constant name ""CLASS_CONST3"" doesn't conform to snake_case naming style"
44
invalid-name:13:4:Foo:"Class constant name ""CLASS_CONST4"" doesn't conform to snake_case naming style"
5+
invalid-name:15:0::"Constant name ""MODULE_CONST"" doesn't conform to snake_case naming style"

0 commit comments

Comments
 (0)