Skip to content

Commit 43c8eb0

Browse files
committed
refactor: parser._multiline is now parser.multiline_map
1 parent d5c8d75 commit 43c8eb0

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

coverage/parser.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(
9292

9393
# A dict mapping line numbers to lexical statement starts for
9494
# multi-line statements.
95-
self._multiline: dict[TLineNo, TLineNo] = {}
95+
self.multiline_map: dict[TLineNo, TLineNo] = {}
9696

9797
# Lazily-created arc data, and missing arc descriptions.
9898
self._all_arcs: set[TArc] | None = None
@@ -115,7 +115,9 @@ def lines_matching(self, regex: str) -> set[TLineNo]:
115115
start, end = match.span()
116116
start_line = last_start_line + self.text.count("\n", last_start, start)
117117
end_line = last_start_line + self.text.count("\n", last_start, end)
118-
matches.update(self._multiline.get(i, i) for i in range(start_line + 1, end_line + 2))
118+
matches.update(
119+
self.multiline_map.get(i, i) for i in range(start_line + 1, end_line + 2)
120+
)
119121
last_start = start
120122
last_start_line = start_line
121123
return matches
@@ -181,7 +183,7 @@ def _raw_parse(self) -> None:
181183
# different line than the first line of the statement,
182184
# so record a multi-line range.
183185
for l in range(first_line, elineno + 1):
184-
self._multiline[l] = first_line
186+
self.multiline_map[l] = first_line
185187
first_line = 0
186188

187189
if ttext.strip() and toktype != tokenize.COMMENT:
@@ -230,9 +232,9 @@ def _raw_parse(self) -> None:
230232
def first_line(self, lineno: TLineNo) -> TLineNo:
231233
"""Return the first line number of the statement including `lineno`."""
232234
if lineno < 0:
233-
lineno = -self._multiline.get(-lineno, -lineno)
235+
lineno = -self.multiline_map.get(-lineno, -lineno)
234236
else:
235-
lineno = self._multiline.get(lineno, lineno)
237+
lineno = self.multiline_map.get(lineno, lineno)
236238
return lineno
237239

238240
def first_lines(self, linenos: Iterable[TLineNo]) -> set[TLineNo]:
@@ -295,7 +297,7 @@ def _analyze_ast(self) -> None:
295297
296298
"""
297299
assert self._ast_root is not None
298-
aaa = AstArcAnalyzer(self.filename, self._ast_root, self.raw_statements, self._multiline)
300+
aaa = AstArcAnalyzer(self.filename, self._ast_root, self.raw_statements, self.multiline_map)
299301
aaa.analyze()
300302
arcs = aaa.arcs
301303
self._with_jump_fixers = aaa.with_jump_fixers()

coverage/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def lines(self) -> set[TLineNo]:
195195

196196
def multiline_map(self) -> dict[TLineNo, TLineNo]:
197197
"""A map of line numbers to first-line in a multi-line statement."""
198-
return self.parser._multiline
198+
return self.parser.multiline_map
199199

200200
def excluded_lines(self) -> set[TLineNo]:
201201
"""Return the line numbers of statements in the file."""

lab/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def one_file(self, options, filename):
103103
marks[4] = "X"
104104
elif lineno in pyparser.excluded:
105105
marks[4] = "×"
106-
if lineno in pyparser._multiline.values():
106+
if lineno in pyparser.multiline_map.values():
107107
marks[5] = "o"
108-
elif lineno in pyparser._multiline.keys():
108+
elif lineno in pyparser.multiline_map.keys():
109109
marks[5] = "."
110110

111111
if arc_chars:

0 commit comments

Comments
 (0)