diff --git a/mypy/messages.py b/mypy/messages.py index bbcc93ebfb25..1e589e1bdf04 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -43,7 +43,6 @@ SYMBOL_FUNCBASE_TYPES, ArgKind, CallExpr, - ClassDef, Context, Expression, FuncDef, @@ -250,20 +249,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)): + """This determines where a type: ignore for a given context has effect.""" + 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: