Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually cherry pick invalid name on global fix #8354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8307.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Prevent emitting ``invalid-name`` for the line on which a ``global`` statement is declared.

Closes #8307
5 changes: 0 additions & 5 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,6 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:

visit_asyncfunctiondef = visit_functiondef

@utils.only_required_for_messages("disallowed-name", "invalid-name")
def visit_global(self, node: nodes.Global) -> None:
for name in node.names:
self._check_name("const", name, node)

@utils.only_required_for_messages(
"disallowed-name",
"invalid-name",
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/g/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ class CLASS():
pass

CLASS()


# Prevent emitting `invalid-name` for the line on which `global` is declared
# https://github.com/PyCQA/pylint/issues/8307

_foo: str = "tomato"
def setup_shared_foo():
global _foo # [global-statement]
_foo = "potato"
1 change: 1 addition & 0 deletions tests/functional/g/globals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ global-statement:60:4:60:19:global_operator_assign:Using the global statement:UN
global-statement:67:4:67:19:global_function_assign:Using the global statement:UNDEFINED
global-statement:77:4:77:15:override_func:Using the global statement:UNDEFINED
global-statement:87:4:87:16:override_class:Using the global statement:UNDEFINED
global-statement:100:4:100:15:setup_shared_foo:Using the global statement:UNDEFINED
2 changes: 1 addition & 1 deletion tests/functional/n/name/name_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class EmbeddedClass:
def test_globals():
"""Names in global statements are also checked."""
global NOT_CORRECT
global AlsoCorrect # [invalid-name]
global AlsoCorrect
NOT_CORRECT = 1
AlsoCorrect = 2

Expand Down
1 change: 0 additions & 1 deletion tests/functional/n/name/name_styles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ invalid-name:53:4:53:38:CorrectClassName.__DunDER_IS_not_free_for_all__:"Method
invalid-name:83:0:83:18::"Class name ""BAD_NAME_FOR_CLASS"" doesn't conform to PascalCase naming style":HIGH
invalid-name:84:0:84:23::"Class name ""NEXT_BAD_NAME_FOR_CLASS"" doesn't conform to PascalCase naming style":HIGH
invalid-name:91:0:91:11::"Class name ""NOT_CORRECT"" doesn't conform to PascalCase naming style":HIGH
invalid-name:97:4:97:22:test_globals:"Constant name ""AlsoCorrect"" doesn't conform to UPPER_CASE naming style":HIGH
invalid-name:110:4:110:21:FooClass.PROPERTY_NAME:"Attribute name ""PROPERTY_NAME"" doesn't conform to snake_case naming style":INFERENCE
invalid-name:116:4:116:30:FooClass.ABSTRACT_PROPERTY_NAME:"Attribute name ""ABSTRACT_PROPERTY_NAME"" doesn't conform to snake_case naming style":INFERENCE
invalid-name:121:4:121:28:FooClass.PROPERTY_NAME_SETTER:"Attribute name ""PROPERTY_NAME_SETTER"" doesn't conform to snake_case naming style":INFERENCE
Expand Down