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

Method sort_messages

mypy/errors.py:1218–1238  ·  view source on GitHub ↗

Sort an array of error messages locally by line number. I.e., sort a run of consecutive messages with the same context by line number, but otherwise retain the general ordering of the messages.

(self, errors: list[ErrorInfo])

Source from the content-addressed store, hash-verified

1216 return result
1217
1218 def sort_messages(self, errors: list[ErrorInfo]) -> list[ErrorInfo]:
1219 """Sort an array of error messages locally by line number.
1220
1221 I.e., sort a run of consecutive messages with the same
1222 context by line number, but otherwise retain the general
1223 ordering of the messages.
1224 """
1225 result: list[ErrorInfo] = []
1226 i = 0
1227 while i < len(errors):
1228 i0 = i
1229 # Find neighbouring errors with the same context and file.
1230 while i + 1 < len(errors) and errors[i + 1].import_ctx == errors[i].import_ctx:
1231 i += 1
1232 i += 1
1233
1234 # Sort the errors specific to a file according to line number and column.
1235 a = sorted(errors[i0:i], key=lambda x: (x.line, x.column))
1236 a = self.sort_within_context(a)
1237 result.extend(a)
1238 return result
1239
1240 def sort_within_context(self, errors: list[ErrorInfo]) -> list[ErrorInfo]:
1241 """For the same location decide which messages to show first/last.

Callers 1

file_messagesMethod · 0.95

Calls 4

sort_within_contextMethod · 0.95
lenFunction · 0.85
sortedFunction · 0.85
extendMethod · 0.80

Tested by

no test coverage detected