Skip to content

Use inline config in the optional error codes docs #17374

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 1 commit into from
Jun 14, 2024
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
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