@@ -1064,20 +1064,6 @@ def enter_attribute_inference_context(self) -> Iterator[None]:
1064
1064
yield None
1065
1065
self .inferred_attribute_types = old_types
1066
1066
1067
- def _is_empty_generator (self , func : FuncItem ) -> bool :
1068
- """
1069
- Checks whether a function's body is 'return; yield' (the yield being added only
1070
- to promote the function into a generator).
1071
- """
1072
- return (
1073
- len (body := func .body .body ) == 2
1074
- and isinstance (ret_stmt := body [0 ], ReturnStmt )
1075
- and (ret_stmt .expr is None or is_literal_none (ret_stmt .expr ))
1076
- and isinstance (expr_stmt := body [1 ], ExpressionStmt )
1077
- and isinstance (yield_expr := expr_stmt .expr , YieldExpr )
1078
- and (yield_expr .expr is None or is_literal_none (yield_expr .expr ))
1079
- )
1080
-
1081
1067
def check_func_def (
1082
1068
self , defn : FuncItem , typ : CallableType , name : str | None , allow_empty : bool = False
1083
1069
) -> None :
@@ -1255,7 +1241,10 @@ def check_func_def(
1255
1241
# have no good way of doing this.
1256
1242
#
1257
1243
# TODO: Find a way of working around this limitation
1258
- if len (expanded ) >= 2 or self ._is_empty_generator (item ):
1244
+ #
1245
+ # We suppress reachability warnings for empty generators (return; yield), since there's
1246
+ # no way to promote a function into a generator except by adding an "unreachable" yield.
1247
+ if len (expanded ) >= 2 or _is_empty_generator (item ):
1259
1248
self .binder .suppress_unreachable_warnings ()
1260
1249
self .accept (item .body )
1261
1250
unreachable = self .binder .is_unreachable ()
@@ -6976,6 +6965,21 @@ def is_literal_not_implemented(n: Expression) -> bool:
6976
6965
return isinstance (n , NameExpr ) and n .fullname == "builtins.NotImplemented"
6977
6966
6978
6967
6968
+ def _is_empty_generator (func : FuncItem ) -> bool :
6969
+ """
6970
+ Checks whether a function's body is 'return; yield' (the yield being added only
6971
+ to promote the function into a generator).
6972
+ """
6973
+ return (
6974
+ len (body := func .body .body ) == 2
6975
+ and isinstance (ret_stmt := body [0 ], ReturnStmt )
6976
+ and (ret_stmt .expr is None or is_literal_none (ret_stmt .expr ))
6977
+ and isinstance (expr_stmt := body [1 ], ExpressionStmt )
6978
+ and isinstance (yield_expr := expr_stmt .expr , YieldExpr )
6979
+ and (yield_expr .expr is None or is_literal_none (yield_expr .expr ))
6980
+ )
6981
+
6982
+
6979
6983
def builtin_item_type (tp : Type ) -> Type | None :
6980
6984
"""Get the item type of a builtin container.
6981
6985
0 commit comments