Skip to content

Commit ca15fd7

Browse files
committed
Allow missing return types for __exit__, __init_subclass__ and __new__
1 parent 20eb4c4 commit ca15fd7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

flake8_missing_annotations/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ class AnnotationVisitor(ast.NodeVisitor):
148148
_state: List[str]
149149
_errors: List[Error]
150150

151+
allowed_no_return_type = {
152+
"__init__",
153+
"__exit__",
154+
"__init_subclass__",
155+
"__new__",
156+
"setup_module",
157+
"teardown_module",
158+
}
159+
151160
def __init__(self):
152161
self._reinit()
153162

@@ -240,10 +249,7 @@ def visit_FunctionDef(self, function: ast.FunctionDef) -> None:
240249

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

243-
if (
244-
not is_test and function.returns is None
245-
and function_name not in {"__init__", "setup_module", "teardown_module"}
246-
):
252+
if not is_test and function.returns is None and function_name not in self.allowed_no_return_type:
247253
offending_arguments.append(_no_return_annotation)
248254

249255
if offending_arguments:

0 commit comments

Comments
 (0)