From d61383eef28aeef5aa4549e9fd53fb4acc0a4855 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 11 Jun 2023 21:08:12 +0100 Subject: [PATCH] Always allow returning Any from lambda (#15413) --- mypy/checker.py | 1 + test-data/unit/check-flags.test | 11 +++++++++++ 2 files changed, 12 insertions(+) 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)