(self, t: Type | None)
| 355 | self.record_line(node.line, kind) |
| 356 | |
| 357 | def type(self, t: Type | None) -> None: |
| 358 | t = get_proper_type(t) |
| 359 | |
| 360 | if not t: |
| 361 | # If an expression does not have a type, it is often due to dead code. |
| 362 | # Don't count these because there can be an unanalyzed value on a line with other |
| 363 | # analyzed expressions, which overwrite the TYPE_UNANALYZED. |
| 364 | self.record_line(self.line, TYPE_UNANALYZED) |
| 365 | return |
| 366 | |
| 367 | if isinstance(t, AnyType) and is_special_form_any(t): |
| 368 | # TODO: What if there is an error in special form definition? |
| 369 | self.record_line(self.line, TYPE_PRECISE) |
| 370 | return |
| 371 | |
| 372 | if isinstance(t, AnyType): |
| 373 | self.log(" !! Any type around line %d" % self.line) |
| 374 | self.num_any_exprs += 1 |
| 375 | self.record_line(self.line, TYPE_ANY) |
| 376 | elif (not self.all_nodes and is_imprecise(t)) or (self.all_nodes and is_imprecise2(t)): |
| 377 | self.log(" !! Imprecise type around line %d" % self.line) |
| 378 | self.num_imprecise_exprs += 1 |
| 379 | self.record_line(self.line, TYPE_IMPRECISE) |
| 380 | else: |
| 381 | self.num_precise_exprs += 1 |
| 382 | self.record_line(self.line, TYPE_PRECISE) |
| 383 | |
| 384 | for typ in get_proper_types(collect_all_inner_types(t)) + [t]: |
| 385 | if isinstance(typ, AnyType): |
| 386 | typ = get_original_any(typ) |
| 387 | if is_special_form_any(typ): |
| 388 | continue |
| 389 | self.type_of_any_counter[typ.type_of_any] += 1 |
| 390 | self.num_any_types += 1 |
| 391 | if self.line in self.any_line_map: |
| 392 | self.any_line_map[self.line].append(typ) |
| 393 | else: |
| 394 | self.any_line_map[self.line] = [typ] |
| 395 | elif isinstance(typ, Instance): |
| 396 | if typ.args: |
| 397 | if any(is_complex(arg) for arg in typ.args): |
| 398 | self.num_complex_types += 1 |
| 399 | else: |
| 400 | self.num_generic_types += 1 |
| 401 | else: |
| 402 | self.num_simple_types += 1 |
| 403 | elif isinstance(typ, FunctionLike): |
| 404 | self.num_function_types += 1 |
| 405 | elif isinstance(typ, TupleType): |
| 406 | if any(is_complex(item) for item in typ.items): |
| 407 | self.num_complex_types += 1 |
| 408 | else: |
| 409 | self.num_tuple_types += 1 |
| 410 | elif isinstance(typ, TypeVarType): |
| 411 | self.num_typevar_types += 1 |
| 412 | |
| 413 | def log(self, string: str) -> None: |
| 414 | self.output.append(string) |
no test coverage detected