Skip to content

Commit f10bfc7

Browse files
ddfishergvanrossum
authored andcommitted
Fix accidentally disallowing empty returns in strict-optional (#1981)
1 parent ef0382e commit f10bfc7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mypy/checker.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1453,10 +1453,7 @@ def visit_return_stmt(self, s: ReturnStmt) -> Type:
14531453
if (self.function_stack[-1].is_generator and isinstance(return_type, AnyType)):
14541454
return None
14551455

1456-
if isinstance(return_type, Void):
1457-
return None
1458-
1459-
if isinstance(return_type, AnyType):
1456+
if isinstance(return_type, (Void, NoneTyp, AnyType)):
14601457
return None
14611458

14621459
if self.typing_mode_full():

test-data/unit/check-optional.test

+8
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,11 @@ def g(x: Optional[int]) -> int:
298298
x = f() # E: Function does not return a value
299299
f() + 1 # E: Function does not return a value
300300
g(f()) # E: Function does not return a value
301+
302+
[case testEmptyReturn]
303+
def f() -> None:
304+
return
305+
306+
[case testReturnNone]
307+
def f() -> None:
308+
return None

0 commit comments

Comments
 (0)