diff --git a/mypy/checker.py b/mypy/checker.py index 7a5f2f9810e4..9c10cd2fc30d 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -1494,9 +1494,6 @@ def is_unannotated_any(t: Type) -> bool: show_untyped = not self.is_typeshed_stub or self.options.warn_incomplete_stub check_incomplete_defs = self.options.disallow_incomplete_defs and has_explicit_annotation if show_untyped and (self.options.disallow_untyped_defs or check_incomplete_defs): - # TODO: changing end line and column here changes this information for the node itself - # fdef.end_line = fdef.line - # fdef.end_column = fdef.column + 1 if fdef.type is None and self.options.disallow_untyped_defs: if not fdef.arguments or ( len(fdef.arguments) == 1 diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 94b5718fded2..8e482c7c84f2 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -979,22 +979,21 @@ def do_func_def( _dummy_fallback, ) - # End position is always the same. end_line = getattr(n, "end_lineno", None) end_column = getattr(n, "end_col_offset", None) - # Determine end of the function definition itself - # Fall back to the end of the function definition including its body + # End line and column span the whole function including its body. + # Determine end of the function definition itself. + # Fall back to the end of the function definition including its body. def_end_line: int | None = n.lineno - # TODO: to go to the end of the function name: n.col_offset + 4 + len(n.name) def_end_column: int | None = n.col_offset returns = n.returns - # use the return type hint if defined + # Use the return type hint if defined. if returns is not None: def_end_line = returns.end_lineno def_end_column = returns.end_col_offset - # otherwise use the last argument in the function definition + # Otherwise use the last argument in the function definition. elif len(args) > 0: last_arg = args[-1] initializer = last_arg.initializer diff --git a/mypy/messages.py b/mypy/messages.py index 2f4fda54d2ee..2532467b86bf 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -259,9 +259,7 @@ def span_from_context(ctx: Context) -> Iterable[int]: end_line = context.end_line if context else -1 end_column = context.end_column if context else -1 - # set end line and column to same as start of context for function definitions - # this avoids errors being reported in IDEs for the whole function - # TODO: figure out if it's possible to find the end of the function definition line + # FuncDef's end includes the body, use the def's end information if available. if isinstance(context, FuncDef): end_line = context.def_end_line # column is 1-based, see also format_messages in errors.py