From 5215a3302034b260cbe36db339e0873ed24fc7a1 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Wed, 11 May 2022 16:29:35 -0500 Subject: [PATCH] Put an upper limit on the time KeyInFileError takes to print itself (about 20 ms) by limiting damerau_levenshtein to 1000 strings. --- src/uproot/exceptions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uproot/exceptions.py b/src/uproot/exceptions.py index 643ea92da..07bc8160e 100644 --- a/src/uproot/exceptions.py +++ b/src/uproot/exceptions.py @@ -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: