Skip to content

Update documentation on --warn-no-return and NoReturn #2920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ Here are some more useful flags:
for functions with ``None`` or ``Any`` return types. Mypy
also currently ignores functions with an empty body or a body that is
just ellipsis (``...``), since these can be valid as abstract methods.
This option is on by default.

- ``--warn-return-any`` causes mypy to generate a warning when returning a value
with type ``Any`` from a function declared with a non- ``Any`` return type.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ overridden by the pattern sections matching the module name.
- ``ignore_errors`` (Boolean, default False) ignores all non-fatal
errors.

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

- ``warn_return_any`` (Boolean, default False) shows a warning when
Expand Down
29 changes: 29 additions & 0 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,35 @@ check against ``None`` in the if condition.

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

.. _noreturn:

The NoReturn type
*****************

Mypy provides support for functions that never return. For
example, a function that unconditionally raises an exception:

.. code-block:: python

from mypy_extensions import NoReturn

def stop() -> NoReturn:
raise Exception('no way')

Mypy will ensure that functions annotated as returning ``NoReturn``
truly never return, either implicitly or explicitly. Mypy will also
recognize that the code after calls to such functions is unreachable
and will behave accordingly:

.. code-block:: python

def f(x: int) -> int:
if x == 0:
return x
stop()
return 'whatever works' # No error in an unreachable block


Class name forward references
*****************************

Expand Down