|
27 | 27 | Type, AnyType, CallableType, Void, FunctionLike, Overloaded, TupleType, TypedDictType,
|
28 | 28 | Instance, NoneTyp, ErrorType, strip_type, TypeType,
|
29 | 29 | UnionType, TypeVarId, TypeVarType, PartialType, DeletedType, UninhabitedType, TypeVarDef,
|
30 |
| - true_only, false_only, function_type |
| 30 | + true_only, false_only, function_type, is_named_instance |
31 | 31 | )
|
32 | 32 | from mypy.sametypes import is_same_type, is_same_types
|
33 | 33 | from mypy.messages import MessageBuilder
|
@@ -606,20 +606,24 @@ def is_implicit_any(t: Type) -> bool:
|
606 | 606 | self.accept(item.body)
|
607 | 607 | unreachable = self.binder.is_unreachable()
|
608 | 608 |
|
609 |
| - if (self.options.warn_no_return and not unreachable |
610 |
| - and not isinstance(self.return_types[-1], (Void, NoneTyp, AnyType)) |
611 |
| - and (defn.is_coroutine or not defn.is_generator)): |
612 |
| - # Control flow fell off the end of a function that was |
613 |
| - # declared to return a non-None type. |
614 |
| - # Allow functions that are entirely pass/Ellipsis. |
615 |
| - if self.is_trivial_body(defn.body): |
616 |
| - pass |
| 609 | + if (self.options.warn_no_return and not unreachable): |
| 610 | + if (defn.is_generator or |
| 611 | + is_named_instance(self.return_types[-1], 'typing.AwaitableGenerator')): |
| 612 | + return_type = self.get_generator_return_type(self.return_types[-1], |
| 613 | + defn.is_coroutine) |
617 | 614 | else:
|
618 |
| - if isinstance(self.return_types[-1], UninhabitedType): |
| 615 | + return_type = self.return_types[-1] |
| 616 | + |
| 617 | + if (not isinstance(return_type, (Void, NoneTyp, AnyType)) |
| 618 | + and not self.is_trivial_body(defn.body)): |
| 619 | + # Control flow fell off the end of a function that was |
| 620 | + # declared to return a non-None type and is not |
| 621 | + # entirely pass/Ellipsis. |
| 622 | + if isinstance(return_type, UninhabitedType): |
619 | 623 | # This is a NoReturn function
|
620 | 624 | self.msg.note(messages.INVALID_IMPLICIT_RETURN, defn)
|
621 | 625 | else:
|
622 |
| - self.msg.note(messages.MISSING_RETURN_STATEMENT, defn) |
| 626 | + self.msg.fail(messages.MISSING_RETURN_STATEMENT, defn) |
623 | 627 |
|
624 | 628 | self.return_types.pop()
|
625 | 629 |
|
|
0 commit comments