File tree 3 files changed +31
-1
lines changed 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -365,6 +365,7 @@ Here are some more useful flags:
365
365
for functions with ``None `` or ``Any `` return types. Mypy
366
366
also currently ignores functions with an empty body or a body that is
367
367
just ellipsis (``... ``), since these can be valid as abstract methods.
368
+ This option is on by default.
368
369
369
370
- ``--warn-return-any `` causes mypy to generate a warning when returning a value
370
371
with type ``Any `` from a function declared with a non- ``Any `` return type.
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ overridden by the pattern sections matching the module name.
165
165
- ``ignore_errors `` (Boolean, default False) ignores all non-fatal
166
166
errors.
167
167
168
- - ``warn_no_return `` (Boolean, default False ) shows errors for
168
+ - ``warn_no_return `` (Boolean, default True ) shows errors for
169
169
missing return statements on some execution paths.
170
170
171
171
- ``warn_return_any `` (Boolean, default False) shows a warning when
Original file line number Diff line number Diff line change @@ -356,6 +356,35 @@ check against ``None`` in the if condition.
356
356
357
357
``--strict-optional `` is experimental and still has known issues.
358
358
359
+ .. _noreturn :
360
+
361
+ The NoReturn type
362
+ *****************
363
+
364
+ Mypy provides support for functions that never return. For
365
+ example, a function that unconditionally raises an exception:
366
+
367
+ .. code-block :: python
368
+
369
+ from mypy_extensions import NoReturn
370
+
371
+ def stop () -> NoReturn:
372
+ raise Exception (' no way' )
373
+
374
+ Mypy will ensure that functions annotated as returning ``NoReturn ``
375
+ truly never return, either implicitly or explicitly. Mypy will also
376
+ recognize that the code after calls to such functions is unreachable
377
+ and will behave accordingly:
378
+
379
+ .. code-block :: python
380
+
381
+ def f (x : int ) -> int :
382
+ if x == 0 :
383
+ return x
384
+ stop()
385
+ return ' whatever works' # No error in an unreachable block
386
+
387
+
359
388
Class name forward references
360
389
*****************************
361
390
You can’t perform that action at this time.
0 commit comments