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

Fix invalid-name regression for class attributes in subclasses #9772

Merged
merged 1 commit into from
Jul 7, 2024
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
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9765.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 1,4 @@
Fix a regression that raised ``invalid-name`` on class attributes merely
overriding invalid names from an ancestor.

Closes #9765
4 changes: 3 additions & 1 deletion pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 491,9 @@ def visit_assignname( # pylint: disable=too-many-branches
self._check_name("variable", node.name, node)

# Check names defined in class scopes
elif isinstance(frame, nodes.ClassDef):
elif isinstance(frame, nodes.ClassDef) and not any(
frame.local_attr_ancestors(node.name)
):
if utils.is_enum_member(node) or utils.is_assign_name_annotated_with(
node, "Final"
):
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/i/invalid/invalid_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 102,10 @@ def test_disable_mixed(
"""Invalid-name will still be raised for other arguments."""
self.foo_bar = fooBar
self.foo_bar2 = fooBar2

def tearDown(self): ... # pylint: disable=invalid-name


class FooBarSubclass(FooBar):
tearDown = FooBar.tearDown
tearDownNotInAncestor = None # [invalid-name]
2 changes: 2 additions & 0 deletions tests/functional/i/invalid/invalid_name.rc
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
[MAIN]
class-attribute-naming-style=snake_case
1 change: 1 addition & 0 deletions tests/functional/i/invalid/invalid_name.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 6,4 @@ invalid-name:66:0:66:68:a_very_very_very_long_function_name_WithCamelCase_to_mak
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:111:4:111:25:FooBarSubclass:"Class attribute name ""tearDownNotInAncestor"" doesn't conform to snake_case naming style":HIGH
Loading