Skip to content

Commit 5dd062a

Browse files
authored
Use inline config in the optional error codes docs (#17374)
This page already says: > The examples in this section use inline configuration But some of these examples predate support for inline configuration of error codes that was added in #13502
1 parent 3d9256b commit 5dd062a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

docs/source/error_code_list2.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Error codes for optional checks
55

66
This section documents various errors codes that mypy generates only
77
if you enable certain options. See :ref:`error-codes` for general
8-
documentation about error codes. :ref:`error-code-list` documents
9-
error codes that are enabled by default.
8+
documentation about error codes and their configuration.
9+
:ref:`error-code-list` documents error codes that are enabled by default.
1010

1111
.. note::
1212

@@ -241,7 +241,7 @@ mypy generates an error if it thinks that an expression is redundant.
241241

242242
.. code-block:: python
243243
244-
# Use "mypy --enable-error-code redundant-expr ..."
244+
# mypy: enable-error-code="redundant-expr"
245245
246246
def example(x: int) -> None:
247247
# Error: Left operand of "and" is always true [redundant-expr]
@@ -268,7 +268,7 @@ example:
268268

269269
.. code-block:: python
270270
271-
# Use "mypy --enable-error-code possibly-undefined ..."
271+
# mypy: enable-error-code="possibly-undefined"
272272
273273
from typing import Iterable
274274
@@ -297,7 +297,7 @@ Using an iterable value in a boolean context has a separate error code
297297

298298
.. code-block:: python
299299
300-
# Use "mypy --enable-error-code truthy-bool ..."
300+
# mypy: enable-error-code="truthy-bool"
301301
302302
class Foo:
303303
pass
@@ -347,7 +347,7 @@ Example:
347347

348348
.. code-block:: python
349349
350-
# Use "mypy --enable-error-code ignore-without-code ..."
350+
# mypy: enable-error-code="ignore-without-code"
351351
352352
class Foo:
353353
def __init__(self, name: str) -> None:
@@ -378,7 +378,7 @@ Example:
378378

379379
.. code-block:: python
380380
381-
# Use "mypy --enable-error-code unused-awaitable ..."
381+
# mypy: enable-error-code="unused-awaitable"
382382
383383
import asyncio
384384
@@ -462,7 +462,7 @@ Example:
462462

463463
.. code-block:: python
464464
465-
# Use "mypy --enable-error-code explicit-override ..."
465+
# mypy: enable-error-code="explicit-override"
466466
467467
from typing import override
468468
@@ -536,7 +536,7 @@ Now users can actually import ``reveal_type`` to make the runtime code safe.
536536

537537
.. code-block:: python
538538
539-
# Use "mypy --enable-error-code unimported-reveal"
539+
# mypy: enable-error-code="unimported-reveal"
540540
541541
x = 1
542542
reveal_type(x) # Note: Revealed type is "builtins.int" \
@@ -546,7 +546,7 @@ Correct usage:
546546

547547
.. code-block:: python
548548
549-
# Use "mypy --enable-error-code unimported-reveal"
549+
# mypy: enable-error-code="unimported-reveal"
550550
from typing import reveal_type # or `typing_extensions`
551551
552552
x = 1

docs/source/error_codes.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ still keep the other two error codes enabled. The overall logic is following:
8787

8888
* Individual config sections *adjust* them per glob/module
8989

90-
* Inline ``# mypy: disable-error-code="..."`` comments can further
91-
*adjust* them for a specific module.
92-
For example: ``# mypy: disable-error-code="truthy-bool, ignore-without-code"``
90+
* Inline ``# mypy: disable-error-code="..."`` and ``# mypy: enable-error-code="..."``
91+
comments can further *adjust* them for a specific file.
92+
For example:
93+
94+
.. code-block:: python
95+
96+
# mypy: enable-error-code="truthy-bool, ignore-without-code"
9397
9498
So one can e.g. enable some code globally, disable it for all tests in
9599
the corresponding config section, and then re-enable it with an inline

0 commit comments

Comments
 (0)