|
57 | 57 |
|
58 | 58 | from mypy import errorcodes as codes, message_registry |
59 | 59 | from mypy.constant_fold import constant_fold_expr |
60 | | -from mypy.errorcodes import PROPERTY_DECORATOR, ErrorCode |
| 60 | +from mypy.errorcodes import PROPERTY_DECORATOR, ErrorCode, MISSING_RETURN_ANNOTATION |
61 | 61 | from mypy.errors import Errors, report_internal_error |
62 | 62 | from mypy.exprtotype import TypeTranslationError, expr_to_unanalyzed_type |
63 | 63 | from mypy.message_registry import ErrorMessage |
@@ -926,6 +926,25 @@ def visit_func_def(self, defn: FuncDef) -> None: |
926 | 926 | with self.inside_except_star_block_set(value=False): |
927 | 927 | self.analyze_func_def(defn) |
928 | 928 |
|
| 929 | + # Missing return annotation check (optional error code) |
| 930 | + from mypy.types import CallableType |
| 931 | + |
| 932 | + if ( |
| 933 | + # Makes sure return type is not specified, ignores lambdas and special cases |
| 934 | + isinstance(defn.type, CallableType) |
| 935 | + and defn.type.ret_type is None |
| 936 | + and any(arg.type_annotation is not None for arg in defn.arguments) |
| 937 | + and defn.name != "__init__" |
| 938 | + and not defn.is_lambda |
| 939 | + and not defn.is_overload |
| 940 | + ): |
| 941 | + self.msg.fail( |
| 942 | + f'Function "{defn.name}" has no return type annotation', |
| 943 | + defn, |
| 944 | + code=MISSING_RETURN_ANNOTATION, |
| 945 | + ) |
| 946 | + |
| 947 | + |
929 | 948 | def function_fullname(self, fullname: str) -> str: |
930 | 949 | if self.current_overload_item is None: |
931 | 950 | return fullname |
|
0 commit comments