MCPcopy Index your code
hub / github.com/python/mypy / render_messages

Method render_messages

mypy/errors.py:1147–1216  ·  view source on GitHub ↗

Translate the messages into a sequence of tuples. Each tuple is of form (path, line, col, severity, message, code). The rendered sequence includes information about error contexts. The path item may be None. If the line item is negative, the line number is not define

(self, file: str, errors: list[ErrorInfo])

Source from the content-addressed store, hash-verified

1145 }
1146
1147 def render_messages(self, file: str, errors: list[ErrorInfo]) -> list[ErrorTuple]:
1148 """Translate the messages into a sequence of tuples.
1149
1150 Each tuple is of form (path, line, col, severity, message, code).
1151 The rendered sequence includes information about error contexts.
1152 The path item may be None. If the line item is negative, the
1153 line number is not defined for the tuple.
1154 """
1155 file = self.simplify_path(file)
1156 result: list[ErrorTuple] = []
1157 prev_import_context: list[tuple[str, int]] = []
1158 prev_function: str | None = None
1159 prev_type: str | None = None
1160
1161 for e in errors:
1162 # Report module import context, if different from previous message.
1163 if not self.options.show_error_context:
1164 pass
1165 elif e.import_ctx != prev_import_context:
1166 last = len(e.import_ctx) - 1
1167 i = last
1168 while i >= 0:
1169 path, line = e.import_ctx[i]
1170 fmt = "{}:{}: note: In module imported here"
1171 if i < last:
1172 fmt = "{}:{}: note: ... from here"
1173 if i > 0:
1174 fmt += ","
1175 else:
1176 fmt += ":"
1177 # Remove prefix to ignore from path (if present) to
1178 # simplify path.
1179 path = remove_path_prefix(path, self.ignore_prefix)
1180 result.append((None, -1, -1, -1, -1, "note", fmt.format(path, line), None))
1181 i -= 1
1182
1183 # Report context within a source file.
1184 type, function = e.local_ctx
1185 if not self.options.show_error_context:
1186 pass
1187 elif function != prev_function or type != prev_type:
1188 if function is None:
1189 if type is None:
1190 result.append((file, -1, -1, -1, -1, "note", "At top level:", None))
1191 else:
1192 result.append((file, -1, -1, -1, -1, "note", f'In class "{type}":', None))
1193 else:
1194
1195 if type is None:
1196 msg = f'In function "{function}":'
1197 else:
1198 msg = 'In member "{}" of class "{}":'.format(function, type)
1199 result.append((file, -1, -1, -1, -1, "note", msg, None))
1200
1201 elif type != prev_type:
1202 if type is None:
1203 result.append((file, -1, -1, -1, -1, "note", "At top level:", None))
1204 else:

Callers 1

file_messagesMethod · 0.95

Calls 5

simplify_pathMethod · 0.95
lenFunction · 0.85
remove_path_prefixFunction · 0.85
appendMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected