diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-04-01 13:46:19 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-04-03 22:17:23 +0200 |
commit | 8b3b8e27c891c4678b2e239c899fb4e12714ab67 (patch) | |
tree | 005f98d0edb30237ca93f66ac6f2ee03d99926a8 | |
parent | 86df139890b13d253185a42c692360d270318c14 (diff) | |
download | pylint-git-8b3b8e27c891c4678b2e239c899fb4e12714ab67.tar.gz |
Apply const-naming-style to module const annotated with Final
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/checkers/base.py | 4 | ||||
-rw-r--r-- | tests/functional/n/name/name_final.py | 3 | ||||
-rw-r--r-- | tests/functional/n/name/name_final.txt | 1 | ||||
-rw-r--r-- | tests/functional/n/name/name_final_snake_case.py | 3 | ||||
-rw-r--r-- | tests/functional/n/name/name_final_snake_case.rc | 1 | ||||
-rw-r--r-- | tests/functional/n/name/name_final_snake_case.txt | 1 |
7 files changed, 16 insertions, 0 deletions
@@ -9,6 +9,9 @@ Release date: Undefined .. Put new features here and also in 'doc/whatsnew/2.8.rst' +* Apply ``const-naming-style`` to module constants annotated with + ``typing.Final`` + What's New in Pylint 2.7.5? =========================== diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 4b8d44fb0..1c54bd42c 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -1983,6 +1983,10 @@ class NameChecker(_BasicChecker): self._check_name("const", node.name, node) elif isinstance(assign_type, astroid.ExceptHandler): self._check_name("variable", node.name, node) + elif isinstance( + assign_type, astroid.AnnAssign + ) and utils.is_assign_name_annotated_with(node, "Final"): + self._check_name("const", node.name, node) elif isinstance(frame, astroid.FunctionDef): # global introduced variable aren't in the function locals if node.name in frame and node.name not in frame.argnames(): diff --git a/tests/functional/n/name/name_final.py b/tests/functional/n/name/name_final.py index b59771a25..60b92ce18 100644 --- a/tests/functional/n/name/name_final.py +++ b/tests/functional/n/name/name_final.py @@ -11,3 +11,6 @@ class Foo: CLASS_CONST3: typing.Final variable2: typing.Final[int] # [invalid-name] CLASS_CONST4: Final[typing.ClassVar[str]] = "valid" + +MODULE_CONST: Final = 1 +module_var: typing.Final[str] = "const" # [invalid-name] diff --git a/tests/functional/n/name/name_final.txt b/tests/functional/n/name/name_final.txt index 32a9a1546..b9fdd20e5 100644 --- a/tests/functional/n/name/name_final.txt +++ b/tests/functional/n/name/name_final.txt @@ -1,2 +1,3 @@ invalid-name:10:4:Foo:"Class constant name ""variable"" doesn't conform to UPPER_CASE naming style" invalid-name:12:4:Foo:"Class constant name ""variable2"" doesn't conform to UPPER_CASE naming style" +invalid-name:16:0::"Constant name ""module_var"" doesn't conform to UPPER_CASE naming style" diff --git a/tests/functional/n/name/name_final_snake_case.py b/tests/functional/n/name/name_final_snake_case.py index 44786fbb7..ddfc3537a 100644 --- a/tests/functional/n/name/name_final_snake_case.py +++ b/tests/functional/n/name/name_final_snake_case.py @@ -11,3 +11,6 @@ class Foo: CLASS_CONST3: typing.Final # [invalid-name] variable2: typing.Final[int] CLASS_CONST4: Final[typing.ClassVar[str]] = "invalid name" # [invalid-name] + +MODULE_CONST: Final = 1 # [invalid-name] +module_var: typing.Final[str] = "const" diff --git a/tests/functional/n/name/name_final_snake_case.rc b/tests/functional/n/name/name_final_snake_case.rc index c43899d74..43700a640 100644 --- a/tests/functional/n/name/name_final_snake_case.rc +++ b/tests/functional/n/name/name_final_snake_case.rc @@ -3,3 +3,4 @@ min_pyver=3.8 [BASIC] class-const-naming-style=snake_case +const-naming-style=snake_case diff --git a/tests/functional/n/name/name_final_snake_case.txt b/tests/functional/n/name/name_final_snake_case.txt index 79f903619..48f03d13b 100644 --- a/tests/functional/n/name/name_final_snake_case.txt +++ b/tests/functional/n/name/name_final_snake_case.txt @@ -2,3 +2,4 @@ invalid-name:8:4:Foo:"Class constant name ""CLASS_CONST"" doesn't conform to sna invalid-name:9:4:Foo:"Class constant name ""CLASS_CONST2"" doesn't conform to snake_case naming style" invalid-name:11:4:Foo:"Class constant name ""CLASS_CONST3"" doesn't conform to snake_case naming style" invalid-name:13:4:Foo:"Class constant name ""CLASS_CONST4"" doesn't conform to snake_case naming style" +invalid-name:15:0::"Constant name ""MODULE_CONST"" doesn't conform to snake_case naming style" |