Skip to content

Commit d2aa2ba

Browse files
committed
Don't peek at our iterator when computing best_match.
Someone added a cool `default` argument to `max`, and all versions we support have it.
1 parent bc3ba8e commit d2aa2ba

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

jsonschema/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from textwrap import dedent, indent
99
from typing import TYPE_CHECKING, Any, ClassVar
1010
import heapq
11-
import itertools
1211
import warnings
1312

1413
from attrs import define
@@ -471,11 +470,9 @@ def best_match(errors, key=relevance):
471470
set of inputs from version to version if better heuristics are added.
472471
473472
"""
474-
errors = iter(errors)
475-
best = next(errors, None)
473+
best = max(errors, key=key, default=None)
476474
if best is None:
477475
return
478-
best = max(itertools.chain([best], errors), key=key)
479476

480477
while best.context:
481478
# Calculate the minimum via nsmallest, because we don't recurse if

0 commit comments

Comments
 (0)