Skip to content

Commit f51090d

Browse files
authored
Make "deprecated" Note a standard Error, disabled by default (#18192)
While working on the relase of mypy 1.14 we noticed a large number of notes for deprecated. Speaking with Jukka, he suggested we make this disabled by default. And if it's disabled by default, having it as a note is not as useful. We also don't have many stand alone notes. Most notes are "attached" with an error. This PR makes the deprecated error disabled by default and by default reports it as error when enabled. `--report-deprecated-as-note` can be used to report them as notes instead.
1 parent 242873a commit f51090d

File tree

9 files changed

+216
-186
lines changed

9 files changed

+216
-186
lines changed

docs/source/command_line.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,12 @@ potentially problematic or redundant in some way.
541541

542542
This limitation will be removed in future releases of mypy.
543543

544-
.. option:: --report-deprecated-as-error
544+
.. option:: --report-deprecated-as-note
545545

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

551551
.. _miscellaneous-strictness-flags:
552552

docs/source/error_code_list2.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ incorrect control flow or conditional checks that are accidentally always true o
236236
Check that imported or used feature is deprecated [deprecated]
237237
--------------------------------------------------------------
238238

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

247247
.. note::
248248

mypy/checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7696,7 +7696,7 @@ def warn_deprecated(self, node: SymbolNode | None, context: Context) -> None:
76967696
and ((deprecated := node.deprecated) is not None)
76977697
and not self.is_typeshed_stub
76987698
):
7699-
warn = self.msg.fail if self.options.report_deprecated_as_error else self.msg.note
7699+
warn = self.msg.note if self.options.report_deprecated_as_note else self.msg.fail
77007700
warn(deprecated, context, code=codes.DEPRECATED)
77017701

77027702

mypy/errorcodes.py

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def __hash__(self) -> int:
308308
"deprecated",
309309
"Warn when importing or using deprecated (overloaded) functions, methods or classes",
310310
"General",
311+
default_enabled=False,
311312
)
312313

313314
# This copy will not include any error codes defined later in the plugins.

mypy/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ def add_invertible_flag(
810810
group=lint_group,
811811
)
812812
add_invertible_flag(
813-
"--report-deprecated-as-error",
813+
"--report-deprecated-as-note",
814814
default=False,
815815
strict_flag=False,
816-
help="Report importing or using deprecated features as errors instead of notes",
816+
help="Report importing or using deprecated features as notes instead of errors",
817817
group=lint_group,
818818
)
819819

mypy/options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self) -> None:
177177
self.warn_return_any = False
178178

179179
# Report importing or using deprecated features as errors instead of notes.
180-
self.report_deprecated_as_error = False
180+
self.report_deprecated_as_note = False
181181

182182
# Warn about unused '# type: ignore' comments
183183
self.warn_unused_ignores = False

mypy/typeanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def check_and_warn_deprecated(self, info: TypeInfo, ctx: Context) -> None:
790790
if isinstance(imp, ImportFrom) and any(info.name == n[0] for n in imp.names):
791791
break
792792
else:
793-
warn = self.fail if self.options.report_deprecated_as_error else self.note
793+
warn = self.note if self.options.report_deprecated_as_note else self.fail
794794
warn(deprecated, ctx, code=codes.DEPRECATED)
795795

796796
def analyze_type_with_type_info(

0 commit comments

Comments
 (0)