(
self,
tree: MypyFile,
modules: dict[str, MypyFile],
type_map: dict[Expression, Type],
options: Options,
)
| 165 | self.counts: dict[str, tuple[int, int, int, int]] = {} |
| 166 | |
| 167 | def on_file( |
| 168 | self, |
| 169 | tree: MypyFile, |
| 170 | modules: dict[str, MypyFile], |
| 171 | type_map: dict[Expression, Type], |
| 172 | options: Options, |
| 173 | ) -> None: |
| 174 | # Count physical lines. This assumes the file's encoding is a |
| 175 | # superset of ASCII (or at least uses \n in its line endings). |
| 176 | if not os.path.isdir(tree.path): # can happen with namespace packages |
| 177 | with open(tree.path, "rb") as f: |
| 178 | physical_lines = len(f.readlines()) |
| 179 | else: |
| 180 | physical_lines = 0 |
| 181 | |
| 182 | func_counter = FuncCounterVisitor() |
| 183 | tree.accept(func_counter) |
| 184 | unannotated_funcs, annotated_funcs = func_counter.counts |
| 185 | total_funcs = annotated_funcs + unannotated_funcs |
| 186 | |
| 187 | # Don't count lines or functions as annotated if they have their errors ignored. |
| 188 | if options.ignore_errors: |
| 189 | annotated_funcs = 0 |
| 190 | |
| 191 | imputed_annotated_lines = ( |
| 192 | physical_lines * annotated_funcs // total_funcs if total_funcs else physical_lines |
| 193 | ) |
| 194 | |
| 195 | self.counts[tree._fullname] = ( |
| 196 | imputed_annotated_lines, |
| 197 | physical_lines, |
| 198 | annotated_funcs, |
| 199 | total_funcs, |
| 200 | ) |
| 201 | |
| 202 | def on_finish(self) -> None: |
| 203 | counts: list[tuple[tuple[int, int, int, int], str]] = sorted( |
nothing calls this directly
no test coverage detected