Skip to content

Commit 7871b8d

Browse files
author
Ilya Priven
committed
support 'return None' and 'yield None'
1 parent 29c3463 commit 7871b8d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mypy/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,10 @@ def _is_empty_generator(self, func: FuncItem) -> bool:
10721072
return (
10731073
len(body := func.body.body) == 2
10741074
and isinstance(ret_stmt := body[0], ReturnStmt)
1075-
and ret_stmt.expr is None
1075+
and (ret_stmt.expr is None or is_literal_none(ret_stmt.expr))
10761076
and isinstance(expr_stmt := body[1], ExpressionStmt)
10771077
and isinstance(yield_expr := expr_stmt.expr, YieldExpr)
1078-
and yield_expr.expr is None
1078+
and (yield_expr.expr is None or is_literal_none(yield_expr.expr))
10791079
)
10801080

10811081
def check_func_def(

test-data/unit/check-unreachable-code.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,3 +1454,11 @@ from typing import Generator
14541454
def f() -> Generator[None, None, None]:
14551455
return
14561456
yield
1457+
1458+
[case testIntentionallyEmptyGenerator_None]
1459+
# flags: --warn-unreachable
1460+
from typing import Generator
1461+
1462+
def f() -> Generator[None, None, None]:
1463+
return None
1464+
yield None

0 commit comments

Comments
 (0)