Skip to content

Commit fe52ee1

Browse files
committed
Preserve original behavior for testLambdaReturningNone
1 parent 5cc0f23 commit fe52ee1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mypy/checkexpr.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ def always_returns_none(self, node: Expression) -> bool:
716716

717717
def defn_returns_none(self, defn: SymbolNode | None) -> bool:
718718
"""Check if `defn` can _only_ return None."""
719+
allow_inferred = False
719720
if isinstance(defn, Decorator):
721+
allow_inferred = True
720722
defn = defn.var
721723
if isinstance(defn, FuncDef):
722724
return isinstance(defn.type, CallableType) and isinstance(
@@ -726,8 +728,10 @@ def defn_returns_none(self, defn: SymbolNode | None) -> bool:
726728
return all(self.defn_returns_none(item) for item in defn.items)
727729
if isinstance(defn, Var):
728730
typ = get_proper_type(defn.type)
729-
if isinstance(typ, CallableType) and isinstance(
730-
get_proper_type(typ.ret_type), NoneType
731+
if (
732+
(allow_inferred or not defn.is_inferred)
733+
and isinstance(typ, CallableType)
734+
and isinstance(get_proper_type(typ.ret_type), NoneType)
731735
):
732736
return True
733737
if isinstance(typ, Instance):

test-data/unit/check-optional.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ reveal_type(z2) # N: Revealed type is "Union[Literal[0], builtins.str, None]"
119119

120120
[case testLambdaReturningNone]
121121
f = lambda: None
122-
x = f() # E: Function does not return a value (it only ever returns None)
123-
reveal_type(x) # N: Revealed type is "Any"
122+
x = f()
123+
reveal_type(x) # N: Revealed type is "None"
124124

125125
[case testNoneArgumentType]
126126
def f(x: None) -> None: pass

0 commit comments

Comments
 (0)