def type(self, t: Optional[Type]) -> None: t = get_proper_type(t) if not t: # If an expression does not have a type, it is often due to dead code. # Don't count these because there can be an unanalyzed value on a line with other # analyzed expressions, which overwrite the TYPE_UNANALYZED. self.record_line(self.line, TYPE_UNANALYZED) return if isinstance(t, AnyType) and is_special_form_any(t): # TODO: What if there is an error in special form definition? self.record_line(self.line, TYPE_PRECISE) return if isinstance(t, AnyType): self.log(' !! Any type around line %d' % self.line) self.num_any_exprs += 1 self.record_line(self.line, TYPE_ANY) elif ((not self.all_nodes and is_imprecise(t)) or (self.all_nodes and is_imprecise2(t))): self.log(' !! Imprecise type around line %d' % self.line) self.num_imprecise_exprs += 1 self.record_line(self.line, TYPE_IMPRECISE) else: self.num_precise_exprs += 1 self.record_line(self.line, TYPE_PRECISE) for typ in get_proper_types(collect_all_inner_types(t)) + [t]: if isinstance(typ, AnyType): typ = get_original_any(typ) if is_special_form_any(typ): continue self.type_of_any_counter[typ.type_of_any] += 1 self.num_any_types += 1 if self.line in self.any_line_map: self.any_line_map[self.line].append(typ) else: self.any_line_map[self.line] = [typ] elif isinstance(typ, Instance): if typ.args: if any(is_complex(arg) for arg in typ.args): self.num_complex_types += 1 else: self.num_generic_types += 1 else: self.num_simple_types += 1 elif isinstance(typ, FunctionLike): self.num_function_types += 1 elif isinstance(typ, TupleType): if any(is_complex(item) for item in typ.items): self.num_complex_types += 1 else: self.num_tuple_types += 1 elif isinstance(typ, TypeVarType): self.num_typevar_types += 1
def type(self, t: Optional[Type]) -> None: if not t: # If an expression does not have a type, it is often due to dead code. # Don't count these because there can be an unanalyzed value on a line with other # analyzed expressions, which overwrite the TYPE_UNANALYZED. self.record_line(self.line, TYPE_UNANALYZED) return if isinstance(t, AnyType) and t.type_of_any == TypeOfAny.special_form: # This is not a real Any type, so don't collect stats for it. return if isinstance(t, AnyType): self.log(' !! Any type around line %d' % self.line) self.num_any_exprs += 1 self.record_line(self.line, TYPE_ANY) elif ((not self.all_nodes and is_imprecise(t)) or (self.all_nodes and is_imprecise2(t))): self.log(' !! Imprecise type around line %d' % self.line) self.num_imprecise_exprs += 1 self.record_line(self.line, TYPE_IMPRECISE) else: self.num_precise_exprs += 1 self.record_line(self.line, TYPE_PRECISE) for typ in collect_all_inner_types(t) + [t]: if isinstance(typ, AnyType): if typ.type_of_any == TypeOfAny.from_another_any: assert typ.source_any assert typ.source_any.type_of_any != TypeOfAny.from_another_any typ = typ.source_any self.type_of_any_counter[typ.type_of_any] += 1 self.num_any_types += 1 if self.line in self.any_line_map: self.any_line_map[self.line].append(typ) else: self.any_line_map[self.line] = [typ] elif isinstance(typ, Instance): if typ.args: if any(is_complex(arg) for arg in typ.args): self.num_complex_types += 1 else: self.num_generic_types += 1 else: self.num_simple_types += 1 elif isinstance(typ, FunctionLike): self.num_function_types += 1 elif isinstance(typ, TupleType): if any(is_complex(item) for item in typ.items): self.num_complex_types += 1 else: self.num_tuple_types += 1 elif isinstance(typ, TypeVarType): self.num_typevar_types += 1
def type(self, t: Optional[Type]) -> None: if not t: # If an expression does not have a type, it is often due to dead code. # Don't count these because there can be an unanalyzed value on a line with other # analyzed expressions, which overwrite the TYPE_UNANALYZED. self.record_line(self.line, TYPE_UNANALYZED) return if isinstance(t, AnyType) and t.type_of_any == TypeOfAny.special_form: # This is not a real Any type, so don't collect stats for it. return if isinstance(t, AnyType): self.log(' !! Any type around line %d' % self.line) self.num_any_exprs += 1 self.record_line(self.line, TYPE_ANY) elif ((not self.all_nodes and is_imprecise(t)) or (self.all_nodes and is_imprecise2(t))): self.log(' !! Imprecise type around line %d' % self.line) self.num_imprecise_exprs += 1 self.record_line(self.line, TYPE_IMPRECISE) else: self.num_precise_exprs += 1 self.record_line(self.line, TYPE_PRECISE) for typ in collect_all_inner_types(t) + [t]: if isinstance(typ, AnyType): if typ.type_of_any == TypeOfAny.from_another_any: assert typ.source_any assert typ.source_any.type_of_any != TypeOfAny.from_another_any typ = typ.source_any self.type_of_any_counter[typ.type_of_any] += 1 self.num_any_types += 1 if self.line in self.any_line_map: self.any_line_map[self.line].append(typ) else: self.any_line_map[self.line] = [typ] elif isinstance(typ, Instance): if typ.args: if any(is_complex(arg) for arg in typ.args): self.num_complex_types += 1 else: self.num_generic_types += 1 else: self.num_simple_types += 1 elif isinstance(typ, FunctionLike): self.num_function_types += 1 elif isinstance(typ, TupleType): if any(is_complex(item) for item in typ.items): self.num_complex_types += 1 else: self.num_tuple_types += 1 elif isinstance(typ, TypeVarType): self.num_typevar_types += 1