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

Method sort_within_context

mypy/errors.py:1240–1265  ·  view source on GitHub ↗

For the same location decide which messages to show first/last. Currently, we only compare within the same error code, to decide the order of various additional notes.

(self, errors: list[ErrorInfo])

Source from the content-addressed store, hash-verified

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.
1242
1243 Currently, we only compare within the same error code, to decide the
1244 order of various additional notes.
1245 """
1246 result = []
1247 i = 0
1248 while i < len(errors):
1249 i0 = i
1250 # Find neighbouring errors with the same position and error code.
1251 while (
1252 i + 1 < len(errors)
1253 and errors[i + 1].line == errors[i].line
1254 and errors[i + 1].column == errors[i].column
1255 and errors[i + 1].end_line == errors[i].end_line
1256 and errors[i + 1].end_column == errors[i].end_column
1257 and errors[i + 1].code == errors[i].code
1258 ):
1259 i += 1
1260 i += 1
1261
1262 # Sort the messages specific to a given error by priority.
1263 a = sorted(errors[i0:i], key=lambda x: x.priority)
1264 result.extend(a)
1265 return result
1266
1267 def remove_duplicates(self, errors: list[ErrorInfo]) -> list[ErrorInfo]:
1268 filtered_errors = []

Callers 1

sort_messagesMethod · 0.95

Calls 3

lenFunction · 0.85
sortedFunction · 0.85
extendMethod · 0.80

Tested by

no test coverage detected