Skip to content

Commit c5c12fa

Browse files
authored
Simplify span_from_context (#20489)
1 parent 7745c7f commit c5c12fa

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

mypy/messages.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
SYMBOL_FUNCBASE_TYPES,
4444
ArgKind,
4545
CallExpr,
46-
ClassDef,
4746
Context,
4847
Expression,
4948
FuncDef,
@@ -250,20 +249,10 @@ def report(
250249
"""
251250

252251
def span_from_context(ctx: Context) -> Iterable[int]:
253-
"""This determines where a type: ignore for a given context has effect.
254-
255-
Current logic is a bit tricky, to keep as much backwards compatibility as
256-
possible. We may reconsider this to always be a single line (or otherwise
257-
simplify it) when we drop Python 3.7.
258-
259-
TODO: address this in follow up PR
260-
"""
261-
if isinstance(ctx, (ClassDef, FuncDef)):
252+
"""This determines where a type: ignore for a given context has effect."""
253+
if not isinstance(ctx, Expression):
262254
return range(ctx.line, ctx.line + 1)
263-
elif not isinstance(ctx, Expression):
264-
return [ctx.line]
265-
else:
266-
return range(ctx.line, (ctx.end_line or ctx.line) + 1)
255+
return range(ctx.line, (ctx.end_line or ctx.line) + 1)
267256

268257
origin_span: Iterable[int] | None
269258
if origin is not None:

0 commit comments

Comments
 (0)