Skip to content

Commit

Permalink
Use inline config in the optional error codes docs (#17374)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hauntsaninja committed Jun 14, 2024
1 parent 3d9256b commit 5dd062a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 10 additions & 10 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Error codes for optional checks

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

.. note::

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

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

.. code-block:: python
# Use "mypy --enable-error-code possibly-undefined ..."
# mypy: enable-error-code="possibly-undefined"
from typing import Iterable
Expand Down Expand Up @@ -297,7 +297,7 @@ Using an iterable value in a boolean context has a separate error code

.. code-block:: python
# Use "mypy --enable-error-code truthy-bool ..."
# mypy: enable-error-code="truthy-bool"
class Foo:
pass
Expand Down Expand Up @@ -347,7 +347,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code ignore-without-code ..."
# mypy: enable-error-code="ignore-without-code"
class Foo:
def __init__(self, name: str) -> None:
Expand Down Expand Up @@ -378,7 +378,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code unused-awaitable ..."
# mypy: enable-error-code="unused-awaitable"
import asyncio
Expand Down Expand Up @@ -462,7 +462,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code explicit-override ..."
# mypy: enable-error-code="explicit-override"
from typing import override
Expand Down Expand Up @@ -536,7 +536,7 @@ Now users can actually import ``reveal_type`` to make the runtime code safe.

.. code-block:: python
# Use "mypy --enable-error-code unimported-reveal"
# mypy: enable-error-code="unimported-reveal"
x = 1
reveal_type(x) # Note: Revealed type is "builtins.int" \
Expand All @@ -546,7 +546,7 @@ Correct usage:

.. code-block:: python
# Use "mypy --enable-error-code unimported-reveal"
# mypy: enable-error-code="unimported-reveal"
from typing import reveal_type # or `typing_extensions`
x = 1
Expand Down
10 changes: 7 additions & 3 deletions docs/source/error_codes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ still keep the other two error codes enabled. The overall logic is following:

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

* Inline ``# mypy: disable-error-code="..."`` comments can further
*adjust* them for a specific module.
For example: ``# mypy: disable-error-code="truthy-bool, ignore-without-code"``
* Inline ``# mypy: disable-error-code="..."`` and ``# mypy: enable-error-code="..."``
comments can further *adjust* them for a specific file.
For example:

.. code-block:: python
# mypy: enable-error-code="truthy-bool, ignore-without-code"
So one can e.g. enable some code globally, disable it for all tests in
the corresponding config section, and then re-enable it with an inline
Expand Down

0 comments on commit 5dd062a

Please sign in to comment.