Skip to content

Commit d5fb882

Browse files
committed
Make deprecated Note a standard Error, disabled by default
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, removes the flag to report it as error and always reports it as error when enabled.
1 parent 499adae commit d5fb882

File tree

10 files changed

+205
-208
lines changed

10 files changed

+205
-208
lines changed

docs/source/command_line.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,6 @@ potentially problematic or redundant in some way.
537537

538538
This limitation will be removed in future releases of mypy.
539539

540-
.. option:: --report-deprecated-as-error
541-
542-
By default, mypy emits notes if your code imports or uses deprecated
543-
features. This flag converts such notes to errors, causing mypy to
544-
eventually finish with a non-zero exit code. Features are considered
545-
deprecated when decorated with ``warnings.deprecated``.
546540

547541
.. _miscellaneous-strictness-flags:
548542

docs/source/error_code_list2.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,12 @@ 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+
specified in `PEP 702 <https://peps.python.org/pep-0702>`_. You can silence single errors via
243244
``# 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.
246245

247246
.. note::
248247

mypy/checker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7696,8 +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
7700-
warn(deprecated, context, code=codes.DEPRECATED)
7699+
self.msg.fail(deprecated, context, code=codes.DEPRECATED)
77017700

77027701

77037702
class CollectArgTypeVarTypes(TypeTraverserVisitor):

mypy/errorcodes.py

Lines changed: 1 addition & 0 deletions
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/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Show error codes for some note-level messages (these usually appear alone
2222
# and not as a comment for a previous error-level message).
23-
SHOW_NOTE_CODES: Final = {codes.ANNOTATION_UNCHECKED, codes.DEPRECATED}
23+
SHOW_NOTE_CODES: Final = {codes.ANNOTATION_UNCHECKED}
2424

2525
# Do not add notes with links to error code docs to errors with these codes.
2626
# We can tweak this set as we get more experience about what is helpful and what is not.

mypy/main.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,6 @@ def add_invertible_flag(
804804
help="Warn about statements or expressions inferred to be unreachable",
805805
group=lint_group,
806806
)
807-
add_invertible_flag(
808-
"--report-deprecated-as-error",
809-
default=False,
810-
strict_flag=False,
811-
help="Report importing or using deprecated features as errors instead of notes",
812-
group=lint_group,
813-
)
814807

815808
# Note: this group is intentionally added here even though we don't add
816809
# --strict to this group near the end.

mypy/options.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ def __init__(self) -> None:
173173
# declared with a precise type
174174
self.warn_return_any = False
175175

176-
# Report importing or using deprecated features as errors instead of notes.
177-
self.report_deprecated_as_error = False
178-
179176
# Warn about unused '# type: ignore' comments
180177
self.warn_unused_ignores = False
181178

mypy/typeanal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +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
794-
warn(deprecated, ctx, code=codes.DEPRECATED)
793+
self.fail(deprecated, ctx, code=codes.DEPRECATED)
795794

796795
def analyze_type_with_type_info(
797796
self, info: TypeInfo, args: Sequence[Type], ctx: Context, empty_tuple_index: bool

0 commit comments

Comments
 (0)