Skip to content
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

Make "deprecated" Note a standard Error, disabled by default #18192

Merged
merged 3 commits into from
Dec 4, 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
10 changes: 5 additions & 5 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,12 @@ potentially problematic or redundant in some way.

This limitation will be removed in future releases of mypy.

.. option:: --report-deprecated-as-error
.. option:: --report-deprecated-as-note

By default, mypy emits notes if your code imports or uses deprecated
features. This flag converts such notes to errors, causing mypy to
eventually finish with a non-zero exit code. Features are considered
deprecated when decorated with ``warnings.deprecated``.
If error code ``deprecated`` is enabled, mypy emits errors if your code
imports or uses deprecated features. This flag converts such errors to
notes, causing mypy to eventually finish with a zero exit code. Features
are considered deprecated when decorated with ``warnings.deprecated``.

.. _miscellaneous-strictness-flags:

Expand Down
10 changes: 5 additions & 5 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ incorrect control flow or conditional checks that are accidentally always true o
Check that imported or used feature is deprecated [deprecated]
--------------------------------------------------------------

By default, mypy generates a note if your code imports a deprecated feature explicitly with a
If you use :option:`--enable-error-code deprecated <mypy --enable-error-code>`,
mypy generates an error if your code imports a deprecated feature explicitly with a
``from mod import depr`` statement or uses a deprecated feature imported otherwise or defined
locally. Features are considered deprecated when decorated with ``warnings.deprecated``, as
specified in `PEP 702 <https://peps.python.org/pep-0702>`_. You can silence single notes via
``# type: ignore[deprecated]`` or turn off this check completely via ``--disable-error-code=deprecated``.
Use the :option:`--report-deprecated-as-error <mypy --report-deprecated-as-error>` option for
more strictness, which turns all such notes into errors.
specified in `PEP 702 <https://peps.python.org/pep-0702>`_.
Use the :option:`--report-deprecated-as-note <mypy --report-deprecated-as-note>` option to
turn all such errors into notes.

.. note::

Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7696,7 +7696,7 @@ def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:
and ((deprecated := node.deprecated) is not None)
and not self.is_typeshed_stub
):
warn = self.msg.fail if self.options.report_deprecated_as_error else self.msg.note
warn = self.msg.note if self.options.report_deprecated_as_note else self.msg.fail
warn(deprecated, context, code=codes.DEPRECATED)


Expand Down
1 change: 1 addition & 0 deletions mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def __hash__(self) -> int:
"deprecated",
"Warn when importing or using deprecated (overloaded) functions, methods or classes",
"General",
default_enabled=False,
)

# This copy will not include any error codes defined later in the plugins.
Expand Down
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,10 @@ def add_invertible_flag(
group=lint_group,
)
add_invertible_flag(
"--report-deprecated-as-error",
"--report-deprecated-as-note",
default=False,
strict_flag=False,
help="Report importing or using deprecated features as errors instead of notes",
help="Report importing or using deprecated features as notes instead of errors",
group=lint_group,
)

Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(self) -> None:
self.warn_return_any = False

# Report importing or using deprecated features as errors instead of notes.
self.report_deprecated_as_error = False
self.report_deprecated_as_note = False

# Warn about unused '# type: ignore' comments
self.warn_unused_ignores = False
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def check_and_warn_deprecated(self, info: TypeInfo, ctx: Context) -> None:
if isinstance(imp, ImportFrom) and any(info.name == n[0] for n in imp.names):
break
else:
warn = self.fail if self.options.report_deprecated_as_error else self.note
warn = self.note if self.options.report_deprecated_as_note else self.fail
warn(deprecated, ctx, code=codes.DEPRECATED)

def analyze_type_with_type_info(
Expand Down
Loading
Loading