Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit b1c9a14

Browse files
committed
review
1 parent b2b8881 commit b1c9a14

File tree

6 files changed

+11
-54
lines changed

6 files changed

+11
-54
lines changed

shared/reports/carryforward.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,11 @@ def generate_carryforward_report(
3737
session_extras: Mapping[str, str] | None = None,
3838
) -> Report:
3939
"""
40-
Generates a carriedforward report starting from report `report`, flags `flags`
41-
and paths `paths`
40+
Generates a carriedforward report by filtering the given `report` in-place,
41+
to only those files and sessions matching the given `flags` and `paths`.
4242
43-
What this function does it basically take a report `report` and creates a new report
44-
from it (so no changes are done in-place). On this new report, it adds all the information
45-
from `report` that relates to sessions that have any of the flags `f`
46-
47-
This way, for example, if none of the sessions in `report` have a flag in `flags`,
48-
it will just produce an empty report
49-
50-
If there are sessions with any of the flags in `flags`, let's call them `relevant_sessions`,
51-
this function will go through all files in `report` that match any of the paths `paths
52-
and build a new 'carriedforward' ReportFile from it, with only the ReportLines
53-
that had at least one LineSession among the `relevant_sessions` (and proper filter out
54-
all the the other sessions from that line). Then all the new EditableReportFile will
55-
be added to the report.
56-
57-
Also, the old sessions are copied over to the new report, with their numbering changed to match
58-
the new session order they are in now (they could be the fifth session before,
59-
and the first session now)
60-
61-
Args:
62-
report (Report): Description
63-
flags (Sequence[str]): Description
64-
65-
Returns:
66-
EditableReport: A new report with only the info related to `flags` on it, as described above
67-
"""
43+
The sessions that are matching the `flags` are being flagged as `carriedforward`,
44+
and other sessions are removed from the report."""
6845
if paths:
6946
matcher = Matcher(paths)
7047
files_to_delete = {

shared/reports/filtered.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def network(self):
165165
if file:
166166
yield fname, make_network_file(file.totals)
167167

168-
def get(self, filename, _else=None):
168+
def get(self, filename):
169169
if not self.should_include(filename):
170-
return _else
170+
return None
171171
if not self.flags:
172172
return self.report.get(filename)
173173
r = self.report.get(filename)

shared/reports/readonly.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ def get_flag_names(self) -> list[str]:
115115
def sessions(self):
116116
return self.inner_report.sessions
117117

118-
@property
119-
def size(self):
120-
return self.inner_report.size
121-
122118
def apply_diff(self, *args, **kwargs):
123119
return self.inner_report.apply_diff(*args, **kwargs)
124120

shared/reports/resources.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,6 @@ def lookup_label_by_id(self, label_id: int) -> str:
173173
def from_chunks(cls, *args, **kwargs):
174174
return cls(*args, **kwargs)
175175

176-
@property
177-
def size(self):
178-
# TODO: this `size` is only used for internal metrics and an ATS announcement,
179-
# so we can work towards just removing this altogether.
180-
size = 0
181-
for file in self:
182-
size += len(file._lines)
183-
return size
184-
185176
def has_precalculated_totals(self):
186177
return self._totals is not None
187178

@@ -261,7 +252,7 @@ def append(self, _file, joined=True):
261252
self._invalidate_caches()
262253
return True
263254

264-
def get(self, filename, **kwargs):
255+
def get(self, filename):
265256
return self._files.get(filename)
266257

267258
def resolve_paths(self, paths: list[tuple[str, str | None]]):
@@ -516,7 +507,7 @@ def does_diff_adjust_tracked_lines(self, diff, future_report, future_diff):
516507
in_future = future_state != "deleted" and path in future_report
517508
if in_past and in_future:
518509
# get the future version
519-
future_file = future_report.get(path, bind=False)
510+
future_file = future_report.get(path)
520511
# if modified
521512
if future_state == "modified":
522513
# shift the lines to "guess" what C was

tests/benchmarks/test_report.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ def do_parse(raw_report_json, raw_chunks):
4040
def do_full_parse(raw_report_json, raw_chunks):
4141
report = do_parse(raw_report_json, raw_chunks)
4242
# full parsing in this case means iterating over everything in the report
43-
# we iterate over `files` and use `get(bind=True)`, as that is caching the
44-
# parsed `ReportFile` instance.
45-
# the `__iter__` method does not do that.
46-
for filename in report.files:
47-
file = report.get(filename, bind=True)
48-
# … however the same is not true for the `ReportLine`s, which are being
49-
# re-parsed *every damn time* :-(
43+
for file in report:
44+
# Which in particular means iterating over every `ReportLine`s,
45+
# which are unfortunately being re-parsed *every damn time* :-(
5046
for _line in file:
5147
pass
5248

tests/unit/reports/test_readonly.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@ def test_get(self, sample_rust_report):
427427
diff=0,
428428
)
429429

430-
def test_size(self, sample_rust_report):
431-
assert sample_rust_report.size == 34
432-
433430
def test_differing_totals_calculation(self, mocker, sample_report):
434431
rust_analyzer = mocker.MagicMock(
435432
get_totals=mocker.MagicMock(return_value=ReportTotals(1, 999))

0 commit comments

Comments
 (0)