|
| 1 | +.. _config-file: |
| 2 | + |
| 3 | +The mypy configuration file |
| 4 | +=========================== |
| 5 | + |
| 6 | +Mypy supports reading configuration settings from a file. By default |
| 7 | +it uses the file ``mypy.ini`` in the current directory; the |
| 8 | +``--config-file`` command-line flag can be used to read a different |
| 9 | +file instead (see :ref:`--config-file <config-file-flag>`). |
| 10 | + |
| 11 | +Most flags correspond closely to :ref:`command-line flags |
| 12 | +<command-line>` but there are some differences in flag names and some |
| 13 | +flags may take a different value based on the file being processed. |
| 14 | + |
| 15 | +The configuration file format is the usual |
| 16 | +`ini file <https://docs.python.org/3.6/library/configparser.html>`_ |
| 17 | +format. It should contain section names in square brackets and flag |
| 18 | +settings of the form `NAME = VALUE`. Comments start with ``#`` |
| 19 | +characters. |
| 20 | + |
| 21 | +- A section named ``[mypy]`` must be present. This specifies |
| 22 | + the global flags. |
| 23 | + |
| 24 | +- Additional sections named ``[mypy-PATTERN1,PATTERN2,...]`` may be |
| 25 | + present, where ``PATTERN1``, ``PATTERN2`` etc. are `filename |
| 26 | + patterns <https://docs.python.org/3.6/library/fnmatch.html>`_ |
| 27 | + separated by commas. These sections specify additional flags that |
| 28 | + only apply to files whose name matches at least one of the patterns. |
| 29 | + |
| 30 | +Global flags |
| 31 | +************ |
| 32 | + |
| 33 | +The following global flags may only be set in the global section |
| 34 | +(``[mypy]``). |
| 35 | + |
| 36 | +- ``python_version`` (string) specifies the Python version used to |
| 37 | + parse and check the target program. The format is ``DIGIT.DIGIT`` |
| 38 | + for example ``2.7``. The default is the version of the Python |
| 39 | + interpreter used to run mypy. |
| 40 | + |
| 41 | +- ``platform`` (string) specifies the OS platform for the target |
| 42 | + program, for example ``darwin`` or ``win32`` (meaning OS X or |
| 43 | + Windows, respectively). The default is the current platform as |
| 44 | + revealed by Python's ``sys.platform`` variable. |
| 45 | + |
| 46 | +- ``custom_typing_module`` (string) specifies the name of an |
| 47 | + alternative module which is to be considered equivalent to the |
| 48 | + ``typing`` module. |
| 49 | + |
| 50 | +- ``warn_incomplete_stub`` (Boolean, default False) warns for missing |
| 51 | + type annotation in typeshed. This is only relevant in combination |
| 52 | + with ``check_untyped_defs``. |
| 53 | + |
| 54 | +- ``warn_redundant_casts`` (Boolean, default False) warns about |
| 55 | + casting an expression to its inferred type. |
| 56 | + |
| 57 | +- ``warn_unused_ignores`` (Boolean, default False) warns about |
| 58 | + unneeded ``# type: ignore`` comments. |
| 59 | + |
| 60 | +- ``strict_optional`` (Boolean, default False) enables experimental |
| 61 | + strict Optional checks. |
| 62 | + |
| 63 | +- ``scripts_are_modules`` (Boolean, default False) makes script ``x`` |
| 64 | + become module ``x`` instead of ``__main__``. This is useful when |
| 65 | + checking multiple scripts in a single run. |
| 66 | + |
| 67 | +- ``verbosity`` (integer, default 0) controls how much debug output |
| 68 | + will be generated. Higher numbers are more verbose. |
| 69 | + |
| 70 | +- ``pdb`` (Boolean, default False) invokes pdb on fatal error. |
| 71 | + |
| 72 | +- ``show_traceback`` (Boolean, default False) shows traceback on fatal |
| 73 | + error. |
| 74 | + |
| 75 | +- ``dump_type_stats`` (Boolean, default False) dumps stats about type |
| 76 | + definitions. |
| 77 | + |
| 78 | +- ``dump_inference_stats`` (Boolean, default False) dumps stats about |
| 79 | + type inference. |
| 80 | + |
| 81 | +- ``fast_parser`` (Boolean, default False) enables the experimental |
| 82 | + fast parser. |
| 83 | + |
| 84 | +- ``incremental`` (Boolean, default False) enables the experimental |
| 85 | + module cache. |
| 86 | + |
| 87 | +- ``cache_dir`` (string, default ``.mypy_cache``) stores module cache |
| 88 | + info in the given folder in incremental mode. |
| 89 | + |
| 90 | +- ``suppress_error_context`` (Boolean, default False) suppresses |
| 91 | + context notes before errors. |
| 92 | + |
| 93 | + |
| 94 | +Per-file flags |
| 95 | +************** |
| 96 | + |
| 97 | +The following flags may vary per file. They may also be specified in |
| 98 | +the global section; the global section provides defaults which are |
| 99 | +overridden by the pattern sections matching the file. |
| 100 | + |
| 101 | +.. note:: |
| 102 | + |
| 103 | + If multiple pattern sections match a file they are processed in |
| 104 | + unspecified order. |
| 105 | + |
| 106 | +- ``silent_imports`` (Boolean, default False) silences complaints |
| 107 | + about :ref:`imports not found <silent-imports>`. |
| 108 | + |
| 109 | +- ``almost_silent`` (Boolean, default False) is similar but |
| 110 | + :ref:`slightly less silent <almost-silent>`. |
| 111 | + |
| 112 | +- ``disallow_untyped_calls`` (Boolean, default False) disallows |
| 113 | + calling functions without type annotations from functions with type |
| 114 | + annotations. |
| 115 | + |
| 116 | +- ``disallow_untyped_defs`` (Boolean, default False) disallows |
| 117 | + defining functions without type annotations or with incomplete type |
| 118 | + annotations. |
| 119 | + |
| 120 | +- ``check_untyped_defs`` (Boolean, default False) type-checks the |
| 121 | + interior of functions without type annotations. |
| 122 | + |
| 123 | +- ``debug_cache`` (Boolean, default False) writes the incremental |
| 124 | + cache JSON files using a more readable, but slower format. |
| 125 | + |
| 126 | +- ``show_none_errors`` (Boolean, default True) shows errors related |
| 127 | + to strict ``None`` checking, if the global ``strict_optional`` flag |
| 128 | + is enabled. |
| 129 | + |
| 130 | +.. note:: |
| 131 | + |
| 132 | + Configuration flags are liable to change between releases. |
0 commit comments