Skip to content

Commit 2859e79

Browse files
committed
REFACTOR: Rename loop variables for clarity and consistency
- Renamed `kw` to `keyword_item` in dataclass config check - Renamed `target` to `target_element` in module import checks - Renamed `alias` to `alias_element` in import many names check - Renamed `usage` to `usage_element` in temp var check - Renamed `verb` to `verb_name` in function verb check - Renamed `item` to `violation_item` in test assertions - Renamed `v` to `cop013_violation` in module level validation test These changes improve code readability by using more descriptive variable names that clearly indicate their purpose
1 parent 69f36d6 commit 2859e79

5 files changed

Lines changed: 56 additions & 21 deletions

File tree

src/community_of_python_flake8_plugin/checks/dataclass_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def has_required_dataclass_params(decorator: ast.expr) -> bool:
2424
if not isinstance(decorator, ast.Call):
2525
return False
2626

27-
keywords: typing.Final = {kw.arg: kw.value for kw in decorator.keywords if isinstance(kw.value, ast.Constant)}
27+
keywords: typing.Final = {
28+
keyword_item.arg: keyword_item.value
29+
for keyword_item in decorator.keywords
30+
if isinstance(keyword_item.value, ast.Constant)
31+
}
2832
kw_only_param: typing.Final = keywords.get("kw_only")
2933
slots_param: typing.Final = keywords.get("slots")
3034
frozen_param: typing.Final = keywords.get("frozen")

src/community_of_python_flake8_plugin/checks/disabled/module_import_many_names.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
def check_module_has_all_declaration(module_node: ast.Module) -> bool:
2020
for statement in module_node.body:
2121
if isinstance(statement, ast.Assign) and any(
22-
isinstance(target, ast.Name) and target.id == "__all__" for target in statement.targets
22+
isinstance(target_element, ast.Name) and target_element.id == "__all__"
23+
for target_element in statement.targets
2324
):
2425
return True
2526
if (
@@ -76,9 +77,9 @@ def validate_import_size(self, ast_node: ast.ImportFrom) -> None:
7677
return
7778

7879
if not any(
79-
check_module_path_exists(f"{module_name}.{alias.name}")
80-
for alias in ast_node.names
81-
if isinstance(alias, ast.alias) and module_name is not None
80+
check_module_path_exists(f"{module_name}.{alias_element.name}")
81+
for alias_element in ast_node.names
82+
if isinstance(alias_element, ast.alias) and module_name is not None
8283
):
8384
self.violations.append(
8485
Violation(

src/community_of_python_flake8_plugin/checks/function_verb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def check_is_ignored_name(identifier: str) -> bool:
1717

1818

1919
def check_is_verb_name(identifier: str) -> bool:
20-
return any(identifier == verb or identifier.startswith(f"{verb}_") for verb in VERB_PREFIXES)
20+
return any(identifier == verb_name or identifier.startswith(f"{verb_name}_") for verb_name in VERB_PREFIXES)
2121

2222

2323
def check_is_property(function_node: ast.AST) -> bool:

src/community_of_python_flake8_plugin/checks/temp_var.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def _check_temporary_variables(self, ast_node: ast.FunctionDef | ast.AsyncFuncti
7373
continue
7474

7575
if (
76-
len([usage for usage in usages if isinstance(usage.ctx, ast.Store)]) == 1
77-
and len([usage for usage in usages if isinstance(usage.ctx, ast.Load)]) == 1
76+
len([usage_element for usage_element in usages if isinstance(usage_element.ctx, ast.Store)]) == 1
77+
and len([usage_element for usage_element in usages if isinstance(usage_element.ctx, ast.Load)]) == 1
7878
and variable_name in usage_and_stores[1]
7979
and not found_temporary_variable
8080
):

tests/test_plugin.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
)
4848
def test_import_stdlib_validations(input_source: str, expected_output: list[str]) -> None:
4949
assert sorted(
50-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
50+
[
51+
violation_item[2].split(" ")[0]
52+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
53+
] # noqa: COP011
5154
) == sorted(expected_output)
5255

5356

@@ -72,7 +75,10 @@ def test_import_stdlib_validations(input_source: str, expected_output: list[str]
7275
)
7376
def test_import_many_names_validations(input_source: str, expected_output: list[str]) -> None:
7477
assert sorted(
75-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
78+
[
79+
violation_item[2].split(" ")[0]
80+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
81+
] # noqa: COP011
7682
) == sorted(expected_output)
7783

7884

@@ -93,7 +99,10 @@ def test_import_many_names_validations(input_source: str, expected_output: list[
9399
)
94100
def test_type_annotation_validations(input_source: str, expected_output: list[str]) -> None:
95101
assert sorted(
96-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
102+
[
103+
violation_item[2].split(" ")[0]
104+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
105+
] # noqa: COP011
97106
) == sorted(expected_output)
98107

99108

@@ -257,7 +266,10 @@ def test_type_annotation_validations(input_source: str, expected_output: list[st
257266
)
258267
def test_naming_validations(input_source: str, expected_output: list[str]) -> None:
259268
assert sorted(
260-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
269+
[
270+
violation_item[2].split(" ")[0]
271+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
272+
] # noqa: COP011
261273
) == sorted(expected_output)
262274

263275

@@ -288,7 +300,10 @@ def test_naming_validations(input_source: str, expected_output: list[str]) -> No
288300
)
289301
def test_variable_usage_validations(input_source: str, expected_output: list[str]) -> None:
290302
assert sorted(
291-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
303+
[
304+
violation_item[2].split(" ")[0]
305+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
306+
] # noqa: COP011
292307
) == sorted(expected_output)
293308

294309

@@ -333,7 +348,10 @@ def test_variable_usage_validations(input_source: str, expected_output: list[str
333348
)
334349
def test_class_validations(input_source: str, expected_output: list[str]) -> None:
335350
assert sorted(
336-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
351+
[
352+
violation_item[2].split(" ")[0]
353+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
354+
] # noqa: COP011
337355
) == sorted(expected_output)
338356

339357

@@ -367,11 +385,14 @@ def test_class_validations(input_source: str, expected_output: list[str]) -> Non
367385
)
368386
def test_module_level_validations(input_source: str, expected_output: list[str]) -> None:
369387
assert [
370-
v
371-
for v in sorted(
372-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()]
388+
cop013_violation
389+
for cop013_violation in sorted(
390+
[
391+
violation_item[2].split(" ")[0]
392+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
393+
]
373394
)
374-
if v == "COP013"
395+
if cop013_violation == "COP013"
375396
] == expected_output
376397

377398

@@ -444,7 +465,10 @@ def test_module_level_validations(input_source: str, expected_output: list[str])
444465
)
445466
def test_dataclass_validations(input_source: str, expected_output: list[str]) -> None:
446467
assert sorted(
447-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
468+
[
469+
violation_item[2].split(" ")[0]
470+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
471+
] # noqa: COP011
448472
) == sorted(expected_output)
449473

450474

@@ -483,7 +507,10 @@ def test_dataclass_validations(input_source: str, expected_output: list[str]) ->
483507
)
484508
def test_module_vs_class_level_assignments(input_source: str, expected_output: list[str]) -> None:
485509
assert sorted(
486-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
510+
[
511+
violation_item[2].split(" ")[0]
512+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
513+
] # noqa: COP011
487514
) == sorted(expected_output)
488515

489516

@@ -499,5 +526,8 @@ def test_module_vs_class_level_assignments(input_source: str, expected_output: l
499526
)
500527
def test_combined_validations(input_source: str, expected_output: list[str]) -> None:
501528
assert sorted(
502-
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
529+
[
530+
violation_item[2].split(" ")[0]
531+
for violation_item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()
532+
] # noqa: COP011
503533
) == sorted(expected_output)

0 commit comments

Comments
 (0)