Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Add end line and column for the function definition itself
  • Loading branch information
mschoettle committed May 6, 2024
commit 8b7802ca49ea347e86e0cf21f63fcb999c351e8c
5 changes: 5 additions & 0 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ class FuncDef(FuncItem, SymbolNode, Statement):
# Present only when a function is decorated with @typing.datasclass_transform or similar
"dataclass_transform_spec",
"docstring",
"def_end_line",
"def_end_column",
)

__match_args__ = ("name", "arguments", "type", "body")
Expand Down Expand Up @@ -778,6 +780,9 @@ def __init__(
self.is_mypy_only = False
self.dataclass_transform_spec: DataclassTransformSpec | None = None
self.docstring: str | None = None
# track the end of the function definition itself
self.def_end_line: int | None = None
self.def_end_column: int | None = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new attributes will also need to be serialized, or they may get lost in incremental mode.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked in nodes.py and no node serializes end_line or end_column. The same for line and column with the exception of the TypeAlias node (it's unclear to me why).

I did a quick test invoking mypy with --incremental --disallow-untyped-defs --show-error-end on the same file twice which resulted in consistent results.


@property
def name(self) -> str:
Expand Down