Skip to content

Commit 08175c3

Browse files
committed
Lint
1 parent 237e8c3 commit 08175c3

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

flake8_missing_annotations/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from domdf_python_tools.paths import PathPlus
3636
from domdf_python_tools.typing import PathLike
3737

38-
__all__ = ["AnnotationVisitor", "Error", "Plugin", "check_file", "indent_join"]
38+
__all__ = ("AnnotationVisitor", "Error", "Plugin", "check_file", "indent_join")
3939

4040
__author__: str = "Dominic Davis-Foster"
4141
__copyright__: str = "2022 Dominic Davis-Foster"
@@ -112,9 +112,11 @@ def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
112112

113113
offences = list(error.offences)
114114

115+
# pylint: disable=loop-global-usage
115116
missing_return_type = _no_return_annotation in offences
116117
if missing_return_type:
117118
offences.remove(_no_return_annotation)
119+
# pylint: enable=loop-global-usage
118120

119121
if offences:
120122
yield (
@@ -125,15 +127,9 @@ def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
125127
)
126128

127129
if missing_return_type:
128-
yield (
129-
error.lineno,
130-
error.col_offset or 0,
131-
f"MAN002 Function {error.function!r} {_no_return_annotation}",
132-
type(self),
133-
)
134-
130+
msg = f"MAN002 Function {error.function!r} {_no_return_annotation}" # pylint: disable=loop-global-usage
131+
yield error.lineno, error.col_offset or 0, msg, type(self)
135132

136-
pytest_fixture_whitelist = ["monkeypatch", "capsys", "request", "pytestconfig"]
137133

138134
_no_return_annotation = "missing return annotation"
139135

@@ -148,6 +144,8 @@ class AnnotationVisitor(ast.NodeVisitor):
148144
_state: List[str]
149145
_errors: List[Error]
150146

147+
pytest_fixture_whitelist = ("monkeypatch", "capsys", "request", "pytestconfig")
148+
151149
allowed_no_return_type = {
152150
"__init__",
153151
"__exit__",
@@ -215,37 +213,41 @@ def visit_FunctionDef(self, function: ast.FunctionDef) -> None:
215213

216214
offending_arguments = []
217215

216+
AttributeNode, NameNode, CallNode = ast.Attribute, ast.Name, ast.Call
217+
218218
decorators = function.decorator_list
219219
is_fixture = False
220220
if decorators:
221221
for deco in decorators:
222-
if isinstance(deco, ast.Name):
222+
if isinstance(deco, NameNode):
223223
if deco.id == "fixture":
224224
is_fixture = True
225-
elif isinstance(deco, ast.Attribute):
226-
if isinstance(deco.value, ast.Name):
225+
elif isinstance(deco, AttributeNode):
226+
if isinstance(deco.value, NameNode):
227227
if deco.value.id == "pytest" and deco.attr == "fixture":
228228
is_fixture = True
229-
elif isinstance(deco, ast.Call):
230-
if isinstance(deco.func, ast.Attribute):
231-
if isinstance(deco.func.value, ast.Name):
229+
elif isinstance(deco, CallNode):
230+
if isinstance(deco.func, AttributeNode):
231+
if isinstance(deco.func.value, NameNode):
232232
if deco.func.value.id == "pytest" and deco.func.attr == "fixture":
233233
is_fixture = True
234234

235235
arg: ast.arg
236236
for arg in args.args:
237237
if arg.annotation is None:
238+
# pylint: disable=loop-invariant-statement
238239
if arg.arg in {"self", "cls"}:
239240
continue
240241

241-
if is_test and arg.arg in pytest_fixture_whitelist:
242+
if is_test and arg.arg in self.pytest_fixture_whitelist:
242243
continue
243244

244-
elif is_fixture and arg.arg in pytest_fixture_whitelist:
245+
elif is_fixture and arg.arg in self.pytest_fixture_whitelist:
245246
continue
246247

247248
elif function_name in {"__exit__"}:
248249
continue
250+
# pylint: enable=loop-invariant-statement
249251

250252
offending_arguments.append(f"argument {arg.arg!r} is missing a type annotation")
251253

flake8_missing_annotations/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
if __name__ == "__main__":
3636
ret = 0
3737

38-
for filename in sys.argv[1:]:
39-
ret |= check_file(filename)
38+
for filename in sys.argv[1:]: # pylint: disable=dotted-import-in-loop
39+
ret |= check_file(filename) # pylint: disable=loop-global-usage
4040

4141
sys.exit(ret)

0 commit comments

Comments
 (0)