Skip to content

Commit 298e88f

Browse files
committed
Fix name length check to properly distinguish attributes from variables
1 parent 17ba52f commit 298e88f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/community_of_python_flake8_plugin/checks/name_length.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,17 @@ def validate_name_length(self, identifier: str, ast_node: ast.stmt, parent_class
9191
return
9292

9393
if len(identifier) < MIN_NAME_LENGTH:
94+
# Determine if this is an attribute (inside a class) or variable (at module level)
95+
is_attribute = parent_class is not None
96+
9497
self.violations.append(
9598
Violation(
9699
line_number=ast_node.lineno,
97100
column_number=ast_node.col_offset,
98101
violation_code=(
99102
ViolationCodes.ATTRIBUTE_NAME_LENGTH
100-
if isinstance(ast_node, ast.AnnAssign)
103+
if is_attribute
101104
else ViolationCodes.VARIABLE_NAME_LENGTH
102-
if isinstance(ast_node, ast.Assign)
103-
else ViolationCodes.ATTRIBUTE_NAME_LENGTH
104105
),
105106
)
106107
)

0 commit comments

Comments
 (0)