From cb815b120e9f677dfe403a8d65073f6beafbe284 Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Sat, 16 Mar 2024 13:35:55 +0330 Subject: [PATCH] slob.py: _resolve_aliases: minimize try..except StopIteration block --- pyglossary/slob.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyglossary/slob.py b/pyglossary/slob.py index b29e32aa9..377486f39 100644 --- a/pyglossary/slob.py +++ b/pyglossary/slob.py @@ -1279,15 +1279,16 @@ def read_key_frag(item: "Blob", default_fragment: str) -> "tuple[str, str]": while count <= self.max_redirects: # is target key itself a redirect? try: - orig_to_key = to_key - to_key, fragment = read_key_frag( - cast(Blob, next(aliases[to_key])), - fragment, - ) - count += 1 - keys.add(orig_to_key) + alias_item: Blob = next(aliases[to_key]) except StopIteration: break + orig_to_key = to_key + to_key, fragment = read_key_frag( + alias_item, + fragment, + ) + count += 1 + keys.add(orig_to_key) if count > self.max_redirects: self._fire_event("too_many_redirects", from_key) target_ref: Ref