| 1 |
.. _inline-config: |
| 2 |
|
| 3 |
Inline configuration |
| 4 |
==================== |
| 5 |
|
| 6 |
Mypy supports setting per-file configuration options inside files themselves |
| 7 |
using ``# mypy:`` comments. For example: |
| 8 |
|
| 9 |
.. code-block:: python |
| 10 |
|
| 11 |
# mypy: disallow-any-generics |
| 12 |
|
| 13 |
Inline configuration comments take precedence over all other |
| 14 |
configuration mechanisms. |
| 15 |
|
| 16 |
Configuration comment format |
| 17 |
**************************** |
| 18 |
|
| 19 |
Flags correspond to :ref:`config file flags <config-file>` but allow |
| 20 |
hyphens to be substituted for underscores. |
| 21 |
|
| 22 |
Values are specified using ``=``, but ``= True`` may be omitted: |
| 23 |
|
| 24 |
.. code-block:: python |
| 25 |
|
| 26 |
# mypy: disallow-any-generics |
| 27 |
# mypy: always-true=FOO |
| 28 |
|
| 29 |
Multiple flags can be separated by commas or placed on separate |
| 30 |
lines. To include a comma as part of an option's value, place the |
| 31 |
value inside quotes: |
| 32 |
|
| 33 |
.. code-block:: python |
| 34 |
|
| 35 |
# mypy: disallow-untyped-defs, always-false="FOO,BAR" |
| 36 |
|
| 37 |
Like in the configuration file, options that take a boolean value may be |
| 38 |
inverted by adding ``no-`` to their name or by (when applicable) |
| 39 |
swapping their prefix from ``disallow`` to ``allow`` (and vice versa): |
| 40 |
|
| 41 |
.. code-block:: python |
| 42 |
|
| 43 |
# mypy: allow-untyped-defs, no-strict-optional |