Skip to content

Don't call --strict-optional and --incremental experimental #4642

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 3 commits into from
Feb 27, 2018
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
45 changes: 18 additions & 27 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,11 @@ Here are some more useful flags:
- ``--ignore-missing-imports`` suppresses error messages about imports
that cannot be resolved (see :ref:`follow-imports` for some examples).

- ``--strict-optional`` enables experimental strict checking of ``Optional[...]``
types and ``None`` values. Without this option, mypy doesn't generally check the
use of ``None`` values -- they are valid everywhere. See :ref:`strict_optional` for
more about this feature.

- ``--strict-optional-whitelist`` attempts to suppress strict Optional-related
errors in non-whitelisted files. Takes an arbitrary number of globs as the
whitelist. This option is intended to be used to incrementally roll out
``--strict-optional`` to a large codebase that already has mypy annotations.
However, this flag comes with some significant caveats. It does not suppress
all errors caused by turning on ``--strict-optional``, only most of them, so
there may still be a bit of upfront work to be done before it can be used in
CI. It will also suppress some errors that would be caught in a
non-strict-Optional run. Therefore, when using this flag, you should also
re-check your code without ``--strict-optional`` to ensure new type errors
are not introduced.
- ``--strict-optional`` enables strict checking of ``Optional[...]``
types and ``None`` values. Without this option, mypy doesn't
generally check the use of ``None`` values -- they are valid
everywhere. See :ref:`strict_optional` for more about this feature.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: depending on how soon, you might want to mention this flag will become default soon.

This flag will become the default in the near future.

- ``--disallow-untyped-defs`` reports an error whenever it encounters
a function definition without type annotations.
Expand Down Expand Up @@ -342,17 +331,19 @@ Here are some more useful flags:

.. _incremental:

- ``--incremental`` is an experimental option that enables a module
cache. When enabled, mypy caches results from previous runs
to speed up type checking. Incremental mode can help when most parts
of your program haven't changed since the previous mypy run. A
companion flag is ``--cache-dir DIR``, which specifies where the
cache files are written. By default this is ``.mypy_cache`` in the
current directory. While the cache is only read in incremental
mode, it is written even in non-incremental mode, in order to "warm"
the cache. To disable writing the cache, use
``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul`` (Windows).
Cache files belonging to a different mypy version are ignored.
- ``--incremental`` enables a module cache, using results from
previous runs to speed up type checking. Incremental mode can help
when most parts of your program haven't changed since the previous
mypy run.

- ``--cache-dir DIR`` is a companion flag to ``-incremental``, which
specifies where the cache files are written. By default this is
``.mypy_cache`` in the current directory. While the cache is only
read in incremental mode, it is written even in non-incremental
mode, in order to "warm" the cache. To disable writing the cache,
use ``--cache-dir=/dev/null`` (UNIX) or ``--cache-dir=nul``
(Windows). Cache files belonging to a different mypy version are
ignored.

.. _quick-mode:

Expand Down
13 changes: 5 additions & 8 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,14 @@ idiomatic.

.. _strict_optional:

Experimental strict optional type and None checking
Strict optional type and None checking
***************************************************

Currently, ``None`` is a valid value for each type, similar to
``null`` or ``NULL`` in many languages. However, you can use the
experimental ``--strict-optional`` command line option to tell mypy
that types should not include ``None``
``--strict-optional`` command line option
(which will become the default in the near future)
to tell mypy that types should not include ``None``
by default. The ``Optional`` type modifier is then used to define
a type variant that includes ``None``, such as ``Optional[int]``:

Expand Down Expand Up @@ -478,10 +479,6 @@ recognizes ``is None`` checks:
Mypy will infer the type of ``x`` to be ``int`` in the else block due to the
check against ``None`` in the if condition.

.. note::

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

.. _noreturn:

The NoReturn type
Expand Down Expand Up @@ -986,7 +983,7 @@ annotated the first example as the following:
def squares(n: int) -> Generator[int, None, None]:
for i in range(n):
yield i * i

This is slightly different from using ``Iterable[int]`` or ``Iterator[int]``,
since generators have ``close()``, ``send()``, and ``throw()`` methods that
generic iterables don't. If you will call these methods on the returned
Expand Down