Skip to content

Commit e502c57

Browse files
committed
ADD support for private verbs and update tests
- Allow function names starting with underscore to be considered verbs - Add "fill" to the list of recognized verb prefixes - Update test cases to reflect new behavior for private verb names - Fix false positive for private methods with verb-like names
1 parent 6736e6f commit e502c57

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/community_of_python_flake8_plugin/checks/function_verb.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
def check_is_ignored_name(identifier: str) -> bool:
1212
if identifier == "main":
1313
return True
14-
if identifier.startswith("__") and identifier.endswith("__"):
15-
return True
16-
return bool(identifier.startswith("_"))
14+
return bool(identifier.startswith("__") and identifier.endswith("__"))
1715

1816

1917
def check_is_verb_name(identifier: str) -> bool:
2018
return any(
21-
identifier == one_verb_name or identifier.startswith(f"{one_verb_name}_") for one_verb_name in VERB_PREFIXES
19+
identifier == one_verb_name or identifier.startswith((f"{one_verb_name}_", f"_{one_verb_name}"))
20+
for one_verb_name in VERB_PREFIXES
2221
)
2322

2423

src/community_of_python_flake8_plugin/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"clear",
111111
"undo",
112112
"cache",
113+
"fill",
113114
}
114115

115116
SCALAR_ANNOTATIONS: typing.Final = {"int", "str", "float", "bool", "bytes", "complex"}

tests/test_plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,14 @@ def test_type_annotation_validations(input_source: str, expected_output: list[st
150150
("class ExampleClass:\n _ = 1", ["COP012"]),
151151
# COP007: Function name must be a verb
152152
("def total_value() -> int:\n return 1", ["COP009"]),
153+
# COP007: Function name must be a verb
154+
("def _total_value() -> int:\n return 1", ["COP009"]),
153155
# No violation: get_ prefix is allowed for sync functions
154156
("def get_user_data() -> str:\n return 'value'", []),
155157
# COP010: Avoid get_ prefix in async function names
156158
("async def get_user_data() -> str:\n return 'value'", ["COP010"]),
157159
# COP009: Function name must be a verb (even with mutable params)
158-
("def fill_values(values: list[int]) -> None:\n values[0] = 1", ["COP009"]),
160+
("def _fill_values(values: list[int]) -> None:\n values[0] = 1", []),
159161
# No violation: pytest fixture annotation is whitelisted
160162
(
161163
"import pytest\n@pytest.fixture\ndef some_fixture(arg: pytest.fixture): pass",

0 commit comments

Comments
 (0)