Skip to content

Commit d8bf6e2

Browse files
authored
Optimize mypy/solve.py with min instead of sort (#18688)
The first value of a stable sort always equivalent to a linear min search (and uses less memory).
1 parent d87f0b2 commit d8bf6e2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mypy/solve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def test(x: U) -> U: ...
350350

351351
# For convenience with current type application machinery, we use a stable
352352
# choice that prefers the original type variables (not polymorphic ones) in SCC.
353-
best = sorted(scc, key=lambda x: (x.id not in original_vars, x.id.raw_id))[0]
353+
best = min(scc, key=lambda x: (x.id not in original_vars, x.id.raw_id))
354354
if isinstance(best, TypeVarType):
355355
return best.copy_modified(values=values, upper_bound=common_upper_bound)
356356
if is_trivial_bound(common_upper_bound_p, allow_tuple=True):

0 commit comments

Comments
 (0)