Skip to content

Commit d61383e

Browse files
ilevkivskyijhance
authored andcommitted
Always allow returning Any from lambda (#15413)
1 parent fa05ab9 commit d61383e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mypy/checker.py

+1
Original file line numberDiff line numberDiff line change
@@ -4270,6 +4270,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
42704270
isinstance(return_type, Instance)
42714271
and return_type.type.fullname == "builtins.object"
42724272
)
4273+
and not is_lambda
42734274
):
42744275
self.msg.incorrectly_returning_any(return_type, s)
42754276
return

test-data/unit/check-flags.test

+11
Original file line numberDiff line numberDiff line change
@@ -2184,3 +2184,14 @@ def f(x: bytes, y: bytearray, z: memoryview) -> None:
21842184
follow_imports = skip
21852185
follow_imports_for_stubs = true
21862186
[builtins fixtures/dict.pyi]
2187+
2188+
[case testReturnAnyLambda]
2189+
# flags: --warn-return-any
2190+
from typing import Any, Callable
2191+
2192+
def cb(f: Callable[[int], int]) -> None: ...
2193+
a: Any
2194+
cb(lambda x: a) # OK
2195+
2196+
fn = lambda x: a
2197+
cb(fn)

0 commit comments

Comments
 (0)