Skip to content

Commit 2e2fe30

Browse files
authored
Don't report "function does not return a value" in dynamic functions (#5683)
Fixes a regression introduced in #5663.
1 parent 87e3c71 commit 2e2fe30

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
315315
self.check_protocol_issubclass(e)
316316
if isinstance(ret_type, UninhabitedType) and not ret_type.ambiguous:
317317
self.chk.binder.unreachable()
318-
if not allow_none_return and self.always_returns_none(e.callee):
318+
# Warn on calls to functions that always return None. The check
319+
# of ret_type is both a common-case optimization and prevents reporting
320+
# the error in dynamic functions (where it will be Any).
321+
if (not allow_none_return and isinstance(ret_type, NoneTyp)
322+
and self.always_returns_none(e.callee)):
319323
self.chk.msg.does_not_return_value(callee_type, e)
320324
return AnyType(TypeOfAny.from_error)
321325
return ret_type

test-data/unit/check-functions.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,3 +2376,10 @@ def Y(x: Optional[str] = X(x_in)): ...
23762376

23772377
xx: Optional[int] = X(x_in)
23782378
[out]
2379+
2380+
[case testNoComplainNoneReturnFromUntyped]
2381+
def foo() -> None:
2382+
pass
2383+
2384+
def lol():
2385+
x = foo()

0 commit comments

Comments
 (0)