From 1d649389a09bf696b5504990e8f6720404f0a781 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 6 Feb 2023 19:01:42 -0800 Subject: [PATCH] LazyLibrary should not contain `Tree`s altering itself during iteration is not a good idea --- masque/library.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/masque/library.py b/masque/library.py index 9b88e55..12d133a 100644 --- a/masque/library.py +++ b/masque/library.py @@ -867,7 +867,7 @@ class LazyLibrary(MutableLibrary): This class is usually used to create a library of Patterns by mapping names to functions which generate or load the relevant `Pattern` object as-needed. """ - dict: Dict[str, Union[Callable[[], 'Pattern'], Callable[[], 'Tree']]] + dict: Dict[str, Callable[[], 'Pattern']] cache: Dict[str, 'Pattern'] _lookups_in_progress: Set[str] @@ -879,7 +879,7 @@ class LazyLibrary(MutableLibrary): def __setitem__( self, key: str, - value: Union['Pattern', Callable[[], 'Pattern'], Callable[[], 'Tree']], + value: Union['Pattern', Callable[[], 'Pattern']], ) -> None: if key in self.dict: raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!') @@ -913,16 +913,8 @@ class LazyLibrary(MutableLibrary): self._lookups_in_progress.add(key) func = self.dict[key] - pat_or_tree = func() + pat = func() self._lookups_in_progress.remove(key) - if isinstance(pat_or_tree, Tree): - tree = pat_or_tree - pat = tree[tree.top] - del tree[tree.top] - self.add(tree) - else: - pat = pat_or_tree - self.cache[key] = pat return pat