Skip to content

Commit 3675be7

Browse files
ilevkivskyiddfisher
authored andcommitted
Update documentation on --warn-no-return and NoReturn (#2920)
Fixes #2919. Fixes #2918.
1 parent b067c4f commit 3675be7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

docs/source/command_line.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ Here are some more useful flags:
365365
for functions with ``None`` or ``Any`` return types. Mypy
366366
also currently ignores functions with an empty body or a body that is
367367
just ellipsis (``...``), since these can be valid as abstract methods.
368+
This option is on by default.
368369

369370
- ``--warn-return-any`` causes mypy to generate a warning when returning a value
370371
with type ``Any`` from a function declared with a non- ``Any`` return type.

docs/source/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ overridden by the pattern sections matching the module name.
165165
- ``ignore_errors`` (Boolean, default False) ignores all non-fatal
166166
errors.
167167

168-
- ``warn_no_return`` (Boolean, default False) shows errors for
168+
- ``warn_no_return`` (Boolean, default True) shows errors for
169169
missing return statements on some execution paths.
170170

171171
- ``warn_return_any`` (Boolean, default False) shows a warning when

docs/source/kinds_of_types.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,35 @@ check against ``None`` in the if condition.
356356

357357
``--strict-optional`` is experimental and still has known issues.
358358

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+
359388
Class name forward references
360389
*****************************
361390

0 commit comments

Comments
 (0)