diff --git a/mypy/checker.py b/mypy/checker.py index c1c31538b7de..4593d5164b3d 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -4270,6 +4270,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None: isinstance(return_type, Instance) and return_type.type.fullname == "builtins.object" ) + and not is_lambda ): self.msg.incorrectly_returning_any(return_type, s) return diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 4a43224260d1..6ec0849146c0 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -2184,3 +2184,14 @@ def f(x: bytes, y: bytearray, z: memoryview) -> None: follow_imports = skip follow_imports_for_stubs = true [builtins fixtures/dict.pyi] + +[case testReturnAnyLambda] +# flags: --warn-return-any +from typing import Any, Callable + +def cb(f: Callable[[int], int]) -> None: ... +a: Any +cb(lambda x: a) # OK + +fn = lambda x: a +cb(fn)