Skip to content

Commit f84f00a

Browse files
authored
Remove get_line() and get_column() functions (#14071)
When I was working on a different PR for Mypy, I came across these functions: ```python def get_line(self) -> int: """Don't use. Use x.line.""" return self.line def get_column(self) -> int: """Don't use. Use x.column.""" return self.column ``` So I just went ahead and removed them.
1 parent 6a7c7cd commit f84f00a

File tree

7 files changed

+8
-16
lines changed

7 files changed

+8
-16
lines changed

mypy/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ def span_from_context(ctx: Context) -> tuple[int, int]:
231231
else:
232232
origin_span = None
233233
self.errors.report(
234-
context.get_line() if context else -1,
235-
context.get_column() if context else -1,
234+
context.line if context else -1,
235+
context.column if context else -1,
236236
msg,
237237
severity=severity,
238238
file=file,

mypy/nodes.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ def set_line(
7171
if end_column is not None:
7272
self.end_column = end_column
7373

74-
def get_line(self) -> int:
75-
"""Don't use. Use x.line."""
76-
return self.line
77-
78-
def get_column(self) -> int:
79-
"""Don't use. Use x.column."""
80-
return self.column
81-
8274

8375
if TYPE_CHECKING:
8476
# break import cycle only needed for mypy

mypy/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def indentation_level(self, line_number: int) -> int | None:
353353
return None
354354

355355
def visit_func_def(self, defn: FuncDef) -> None:
356-
start_line = defn.get_line() - 1
356+
start_line = defn.line - 1
357357
start_indent = None
358358
# When a function is decorated, sometimes the start line will point to
359359
# whitespace or comments between the decorator and the function, so

mypy/semanal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6109,12 +6109,12 @@ def fail(
61096109
return
61106110
# In case it's a bug and we don't really have context
61116111
assert ctx is not None, msg
6112-
self.errors.report(ctx.get_line(), ctx.get_column(), msg, blocker=blocker, code=code)
6112+
self.errors.report(ctx.line, ctx.column, msg, blocker=blocker, code=code)
61136113

61146114
def note(self, msg: str, ctx: Context, code: ErrorCode | None = None) -> None:
61156115
if not self.in_checked_function():
61166116
return
6117-
self.errors.report(ctx.get_line(), ctx.get_column(), msg, severity="note", code=code)
6117+
self.errors.report(ctx.line, ctx.column, msg, severity="note", code=code)
61186118

61196119
def incomplete_feature_enabled(self, feature: str, ctx: Context) -> bool:
61206120
if feature not in self.options.enable_incomplete_feature:

mypy/semanal_typeargs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,4 @@ def check_type_var_values(
164164
)
165165

166166
def fail(self, msg: str, context: Context, *, code: ErrorCode | None = None) -> None:
167-
self.errors.report(context.get_line(), context.get_column(), msg, code=code)
167+
self.errors.report(context.line, context.column, msg, code=code)

mypy/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def visit_func_def(self, o: FuncDef) -> None:
149149
if o in o.expanded:
150150
print(
151151
"{}:{}: ERROR: cycle in function expansion; skipping".format(
152-
self.filename, o.get_line()
152+
self.filename, o.line
153153
)
154154
)
155155
return

mypy/strconv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def dump(self, nodes: Sequence[object], obj: mypy.nodes.Context) -> str:
5050
number. See mypy.util.dump_tagged for a description of the nodes
5151
argument.
5252
"""
53-
tag = short_type(obj) + ":" + str(obj.get_line())
53+
tag = short_type(obj) + ":" + str(obj.line)
5454
if self.show_ids:
5555
assert self.id_mapper is not None
5656
tag += f"<{self.get_id(obj)}>"

0 commit comments

Comments
 (0)