| 250 | self._report_types_of_anys() |
| 251 | |
| 252 | def _write_out_report( |
| 253 | self, filename: str, header: list[str], rows: list[list[str]], footer: list[str] |
| 254 | ) -> None: |
| 255 | row_len = len(header) |
| 256 | assert all(len(row) == row_len for row in rows + [header, footer]) |
| 257 | min_column_distance = 3 # minimum distance between numbers in two columns |
| 258 | widths = [-1] * row_len |
| 259 | for row in rows + [header, footer]: |
| 260 | for i, value in enumerate(row): |
| 261 | widths[i] = max(widths[i], len(value)) |
| 262 | for i, w in enumerate(widths): |
| 263 | # Do not add min_column_distance to the first column. |
| 264 | if i > 0: |
| 265 | widths[i] = w + min_column_distance |
| 266 | with open(os.path.join(self.output_dir, filename), "w") as f: |
| 267 | header_str = ("{:>{}}" * len(widths)).format(*itertools.chain(*zip(header, widths))) |
| 268 | separator = "-" * len(header_str) |
| 269 | f.write(header_str + "\n") |
| 270 | f.write(separator + "\n") |
| 271 | for row_values in rows: |
| 272 | r = ("{:>{}}" * len(widths)).format(*itertools.chain(*zip(row_values, widths))) |
| 273 | f.write(r + "\n") |
| 274 | f.write(separator + "\n") |
| 275 | footer_str = ("{:>{}}" * len(widths)).format(*itertools.chain(*zip(footer, widths))) |
| 276 | f.write(footer_str + "\n") |
| 277 | |
| 278 | def _report_any_exprs(self) -> None: |
| 279 | total_any = sum(num_any for num_any, _ in self.counts.values()) |