Skip to content

Document --allow-redefinition #6345

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 2 commits into from
Feb 6, 2019
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
15 changes: 15 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@ of the above sections.
This flag causes mypy to suppress errors caused by not being able to fully
infer the types of global and class variables.

``--allow-redefinition``
By default, mypy won't allow a variable to be redefined with an
unrelated type. This flag enables redefinion of a variable with an
arbitrary type *in some contexts*: only redefinitions within the
same block and nesting depth as the original definition are allowed.
Example where this can be useful:

.. code-block:: python

def process(items: List[str]) -> None:
# 'items' has type List[str]
items = [item.split() for item in items]
# 'items' now has type List[List[str]]
...

``--strict``
This flag mode enables all optional error checking flags. You can see the
list of flags enabled by strict mode in the full ``mypy --help`` output.
Expand Down
46 changes: 25 additions & 21 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ assume here is some 3rd party library you've installed and are importing. These
1. Selectively disallow untyped function definitions only within the ``mycode.foo``
package -- that is, only for function definitions defined in the
``mycode/foo`` directory.
2. Selectively *disable* the "function is returning any" warnings within

2. Selectively *disable* the "function is returning any" warnings within
``mycode.bar`` only. This overrides the global default we set earlier.

3. Suppress any error messages generated when your codebase tries importing the
Expand Down Expand Up @@ -155,22 +155,22 @@ Note: this section describes options that can be used both globally and per-modu
See below for a list of import discovery options that may be used
:ref:`only globally <config-file-import-discovery-global>`.

``ignore_missing_imports`` (bool, default False)
``ignore_missing_imports`` (bool, default False)
Suppresses error messages about imports that cannot be resolved.

If this option is used in a per-module section, the module name should
match the name of the *imported* module, not the module containing the
import statement.

``follow_imports`` (string, default ``normal``)
``follow_imports`` (string, default ``normal``)
Directs what to do with imports when the imported module is found
as a ``.py`` file and not part of the files, modules and packages
as a ``.py`` file and not part of the files, modules and packages
provided on the command line.

The four possible values are ``normal``, ``silent``, ``skip`` and
``error``. For explanations see the discussion for the
:ref:`--follow-imports <follow-imports>` command line flag.
:ref:`--follow-imports <follow-imports>` command line flag.

If this option is used in a per-module section, the module name should
match the name of the *imported* module, not the module containing the
import statement.
Expand Down Expand Up @@ -228,7 +228,7 @@ section of the command line docs.
annotations.

``disallow_incomplete_defs`` (bool, default False)
Disallows defining functions with incomplete type annotations.
Disallows defining functions with incomplete type annotations.

``check_untyped_defs`` (bool, default False)
Type-checks the interior of functions without type annotations.
Expand Down Expand Up @@ -265,7 +265,7 @@ section of the command line docs.
``warn_unused_ignores`` (bool, default False)
Warns about unneeded ``# type: ignore`` comments.

``warn_no_return`` (bool, default True)
``warn_no_return`` (bool, default True)
Shows errors for missing return statements on some execution paths.

``warn_return_any`` (bool, default False)
Expand All @@ -287,6 +287,12 @@ no analog available via the command line options.
``ignore_errors`` (bool, default False)
Ignores all non-fatal errors.

Miscellaneous strictness flags
------------------------------

``allow_redefinition`` (bool, default false)
Allows variables to be redefined with an arbitrary type, as long as the redefinition
is in the same block and nesting level as the original definition.

Global-only options
*******************
Expand All @@ -302,7 +308,7 @@ For more information, see the :ref:`import discovery <import-discovery>`
section of the command line docs.

Note: this section describes only global-only import discovery options. See above for
a list of import discovery options that may be used
a list of import discovery options that may be used
:ref:`both per-module and globally <config-file-import-discovery-per-module>`.

``namespace_packages`` (bool, default False)
Expand Down Expand Up @@ -330,7 +336,7 @@ Platform configuration
For more information, see the :ref:`platform configuration <platform-configuration>`
section of the command line docs.

``python_version`` (string)
``python_version`` (string)
Specifies the Python version used to parse and check the target
program. The string should be in the format ``DIGIT.DIGIT`` --
for example ``2.7``. The default is the version of the Python
Expand All @@ -343,11 +349,11 @@ section of the command line docs.
``sys.platform`` variable.

``always_true`` (comma-separated list of strings)
Specifies a list of variables that mypy will treat as
Specifies a list of variables that mypy will treat as
compile-time constants that are always true.
``always_false`` (comma-separated list of strings)
Specifies a list of variables that mypy will treat as

``always_false`` (comma-separated list of strings)
Specifies a list of variables that mypy will treat as
compile-time constants that are always false.


Expand All @@ -357,10 +363,10 @@ Incremental mode
For more information, see the :ref:`incremental mode <incremental>`
section of the command line docs.

``incremental`` (bool, default True)
``incremental`` (bool, default True)
Enables :ref:`incremental mode <incremental>`.

``cache_dir`` (string, default ``.mypy_cache``)
``cache_dir`` (string, default ``.mypy_cache``)
Specifies the location where mypy stores incremental cache info.
Note that the cache is only read when incremental mode is enabled
but is always written to, unless the value is set to ``/dev/nul``
Expand All @@ -378,7 +384,7 @@ Configuring error messages
For more information, see the :ref:`configuring error messages <configuring-error-messages>`
section of the command line docs.

``show_error_context`` (bool, default False)
``show_error_context`` (bool, default False)
Prefixes each error with the relevant context.

``show_column_numbers`` (bool, default False)
Expand All @@ -397,7 +403,7 @@ section of the command line docs.
``show_traceback`` (bool, default False)
Shows traceback on fatal error.

``custom_typing_module`` (string)
``custom_typing_module`` (string)
Specifies a custom module to use as a substitute for the ``typing`` module.

``custom_typeshed_dir`` (string)
Expand Down Expand Up @@ -425,5 +431,3 @@ Miscellaneous

``verbosity`` (integer, default 0)
Controls how much debug output will be generated. Higher numbers are more verbose.