Skip to content

Commit

Permalink
Optimize mypy/solve.py with min instead of sort (#18688)
Browse files Browse the repository at this point in the history
The first value of a stable sort always equivalent to a linear min
search (and uses less memory).
  • Loading branch information
Skylion007 authored Feb 20, 2025
1 parent d87f0b2 commit d8bf6e2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test(x: U) -> U: ...

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

0 comments on commit d8bf6e2

Please sign in to comment.