Skip to content

Commit

Permalink
Preserve original behavior for testLambdaReturningNone
Browse files Browse the repository at this point in the history
  • Loading branch information
brianschubert committed Oct 22, 2024
1 parent 5cc0f23 commit fe52ee1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ def always_returns_none(self, node: Expression) -> bool:

def defn_returns_none(self, defn: SymbolNode | None) -> bool:
"""Check if `defn` can _only_ return None."""
allow_inferred = False
if isinstance(defn, Decorator):
allow_inferred = True
defn = defn.var
if isinstance(defn, FuncDef):
return isinstance(defn.type, CallableType) and isinstance(
Expand All @@ -726,8 +728,10 @@ def defn_returns_none(self, defn: SymbolNode | None) -> bool:
return all(self.defn_returns_none(item) for item in defn.items)
if isinstance(defn, Var):
typ = get_proper_type(defn.type)
if isinstance(typ, CallableType) and isinstance(
get_proper_type(typ.ret_type), NoneType
if (
(allow_inferred or not defn.is_inferred)
and isinstance(typ, CallableType)
and isinstance(get_proper_type(typ.ret_type), NoneType)
):
return True
if isinstance(typ, Instance):
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ reveal_type(z2) # N: Revealed type is "Union[Literal[0], builtins.str, None]"

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

[case testNoneArgumentType]
def f(x: None) -> None: pass
Expand Down

0 comments on commit fe52ee1

Please sign in to comment.