Skip to content

Commit

Permalink
Put an upper limit on the time KeyInFileError takes to print itself (…
Browse files Browse the repository at this point in the history
…about 20 ms) by limiting damerau_levenshtein to 1000 strings. (#595)
  • Loading branch information
jpivarski authored May 11, 2022
1 parent e966e20 commit 1f2e5d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/uproot/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ def __str__(self):
with_keys = ""
if self.keys is not None:
to_show = None
keys = self.keys
cut = 1
while len(keys) > 1000 and cut < len(self.key):
keys = [x for x in keys if x[:cut] == self.key[:cut]]
cut += 1
sorted_keys = sorted(
self.keys, key=lambda x: uproot._util.damerau_levenshtein(self.key, x)
keys, key=lambda x: uproot._util.damerau_levenshtein(self.key, x)
)
for key in sorted_keys:
if to_show is None:
Expand Down

0 comments on commit 1f2e5d2

Please sign in to comment.