From b7d6d1d7101b2177c73d8d1d8cccb1dfd7ddb057 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 29 Dec 2025 16:53:57 -0800 Subject: [PATCH 1/2] Simplify span_from_context --- mypy/messages.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index bbcc93ebfb25b..bf1b79d287203 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -251,19 +251,10 @@ def report( def span_from_context(ctx: Context) -> Iterable[int]: """This determines where a type: ignore for a given context has effect. - - Current logic is a bit tricky, to keep as much backwards compatibility as - possible. We may reconsider this to always be a single line (or otherwise - simplify it) when we drop Python 3.7. - - TODO: address this in follow up PR """ - if isinstance(ctx, (ClassDef, FuncDef)): + if not isinstance(ctx, Expression): return range(ctx.line, ctx.line + 1) - elif not isinstance(ctx, Expression): - return [ctx.line] - else: - return range(ctx.line, (ctx.end_line or ctx.line) + 1) + return range(ctx.line, (ctx.end_line or ctx.line) + 1) origin_span: Iterable[int] | None if origin is not None: From 0e6257ccc60a521751f45ef93c0779e062ce2c43 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Dec 2025 00:56:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/messages.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index bf1b79d287203..1e589e1bdf042 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -43,7 +43,6 @@ SYMBOL_FUNCBASE_TYPES, ArgKind, CallExpr, - ClassDef, Context, Expression, FuncDef, @@ -250,8 +249,7 @@ def report( """ def span_from_context(ctx: Context) -> Iterable[int]: - """This determines where a type: ignore for a given context has effect. - """ + """This determines where a type: ignore for a given context has effect.""" if not isinstance(ctx, Expression): return range(ctx.line, ctx.line + 1) return range(ctx.line, (ctx.end_line or ctx.line) + 1)