From 90e4d88cd4883dd015a511d7f8e1e7e09e062ac4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 10 Feb 2021 10:23:29 +0100 Subject: buffers/search: do not pass dbman into IterWalker Use functools.partial to keep the widget construction logic out of IterWalker, since it should not handle such details. --- alot/buffers/search.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/alot/buffers/search.py b/alot/buffers/search.py index 20c0ae47..700ce69f 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -3,6 +3,7 @@ # For further details see the COPYING file import asyncio +from functools import partial import urwid @@ -18,7 +19,8 @@ class IterWalker(urwid.ListWalker): ThreadlineWidget widgets for displaying """ - _dbman = None + _threads = None + _wgt_factory = None _iter_done = False @@ -29,9 +31,9 @@ class IterWalker(urwid.ListWalker): _focus = None - def __init__(self, threads, dbman): - self._threads = threads - self._dbman = dbman + def __init__(self, threads, wgt_factory): + self._threads = threads + self._wgt_factory = wgt_factory self._tids = [] self._wgts = {} @@ -51,7 +53,7 @@ class IterWalker(urwid.ListWalker): # make sure an exception while constructing the widget does not get # swallowed by urwid try: - self._wgts[pos] = ThreadlineWidget(self._tids[pos], self._dbman) + self._wgts[pos] = self._wgt_factory(self._tids[pos]) except (KeyError, IndexError, TypeError) as e: raise ValueError('Exception while constructing threadline widget') from e @@ -163,9 +165,10 @@ class SearchBuffer(Buffer): self._result_count = None self._thread_count = None - threads = self.dbman.get_threads(self.querystring, self.sort_order, - exclude_tags) - threadlist = IterWalker(threads, self.dbman) + threads = self.dbman.get_threads(self.querystring, self.sort_order, + exclude_tags) + wgt_factory = partial(ThreadlineWidget, dbman = self.dbman) + threadlist = IterWalker(threads, wgt_factory) # check that the query is well-formed try: -- cgit v1.2.3