@@ -136,6 +136,63 @@ def f() -> int:
136136 return 0
137137[builtins fixtures/bool.pyi]
138138
139+ [case testNoReturnDisallowsReturn]
140+ # flags: --warn-no-return
141+ from mypy_extensions import NoReturn
142+
143+ def f() -> NoReturn:
144+ if bool():
145+ return 5 # E: Return statement in function which does not return
146+ else:
147+ return # E: Return statement in function which does not return
148+ [builtins fixtures/dict.pyi]
149+
150+ [case testNoReturnWithoutImplicitReturn]
151+ # flags: --warn-no-return
152+ from mypy_extensions import NoReturn
153+
154+ def no_return() -> NoReturn: pass
155+ def f() -> NoReturn:
156+ no_return()
157+ [builtins fixtures/dict.pyi]
158+
159+ [case testNoReturnDisallowsImplicitReturn]
160+ # flags: --warn-no-return
161+ from mypy_extensions import NoReturn
162+
163+ def f() -> NoReturn: # N: Implicit return in function which does not return
164+ non_trivial_function = 1
165+ [builtins fixtures/dict.pyi]
166+
167+ [case testNoReturnNoWarnNoReturn]
168+ # flags: --warn-no-return
169+ from mypy_extensions import NoReturn
170+
171+ def no_return() -> NoReturn: pass
172+ def f() -> int:
173+ if bool():
174+ return 0
175+ else:
176+ no_return()
177+ [builtins fixtures/dict.pyi]
178+
179+ [case testNoReturnInExpr]
180+ # flags: --warn-no-return
181+ from mypy_extensions import NoReturn
182+
183+ def no_return() -> NoReturn: pass
184+ def f() -> int:
185+ return 0
186+ reveal_type(f() or no_return()) # E: Revealed type is 'builtins.int'
187+ [builtins fixtures/dict.pyi]
188+
189+ [case testNoReturnVariable]
190+ # flags: --warn-no-return
191+ from mypy_extensions import NoReturn
192+
193+ x = 0 # type: NoReturn # E: Incompatible types in assignment (expression has type "int", variable has type NoReturn)
194+ [builtins fixtures/dict.pyi]
195+
139196[case testShowErrorContextFunction]
140197# flags: --show-error-context
141198def f() -> None:
0 commit comments