From e6f3145ef5559e2ffdf3e279082dbb5bbd4bc9e1 Mon Sep 17 00:00:00 2001 From: dipetm Date: Fri, 7 Aug 2026 15:29:24 +0300 Subject: [PATCH] Trim the comments and drop a test that guarded nothing One rationale in one place instead of three, and the class attribute no longer describes the per-key build that is gone. test_unknown_key_raises only exercised dict lookup and passed unchanged on develop. --- glances/plugins/plugin/model.py | 16 +++++++--------- glances/plugins/processlist/__init__.py | 4 ++-- tests/test_lazy_views.py | 6 ------ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/glances/plugins/plugin/model.py b/glances/plugins/plugin/model.py index 600481bf..829371f7 100644 --- a/glances/plugins/plugin/model.py +++ b/glances/plugins/plugin/model.py @@ -56,8 +56,8 @@ fields_unit_type = { class GlancesPluginModel: """Main class for Glances plugin model.""" - # Build the per-item views on demand instead of up front. Only worth it for plugins whose - # item count is large and unrelated to how many rows the UI shows. + # Defer building the views until something reads them. Worth it for a plugin holding far + # more items than the UI draws, whose own rendering does not consult them. lazy_views = False def __init__(self, args=None, config=None, items_history_list=None, stats_init_value={}, fields_description=None): @@ -121,7 +121,7 @@ class GlancesPluginModel: # Init the views self.views = {} - # Stats whose views have not been built yet (see update_views) + # Set by update_views() when the build is deferred; consumed by get_views() self._views_source = None # Hide stats if all the hide_zero_fields has never been != 0 @@ -673,10 +673,8 @@ class GlancesPluginModel: 'splittable': False, >>> Is the stat can be cut (like process lon name) 'hidden': False} >>> Is the stats should be hidden in the UI """ - # A lazy plugin holds far more items than the UI shows and nothing reads its views - # while drawing, so remember the stats and let get_views() do the work if it is ever - # asked for. hide_zero is excluded: it carries the hidden flag over from the previous - # views, which are gone by the time a deferred build runs. + # hide_zero is excluded: it carries the hidden flag over from the previous views, + # which a deferred build no longer has. if self.lazy_views and not self.hide_zero and isinstance(self.get_raw(), list) and self.get_key() is not None: self._views_source = self.get_raw() self.views = {} @@ -687,8 +685,8 @@ class GlancesPluginModel: return self.views def _build_views(self, raw): - """Build the views for raw stats. Reads self.views, which still holds the previous - views at this point; hide_zero relies on that to keep a field hidden.""" + """self.views still holds the previous views here; hide_zero reads them to keep a + field hidden once it has been hidden.""" ret = {} if raw is not None and isinstance(raw, list) and self.get_key() is not None: diff --git a/glances/plugins/processlist/__init__.py b/glances/plugins/processlist/__init__.py index 1fd8dd56..57b98653 100644 --- a/glances/plugins/processlist/__init__.py +++ b/glances/plugins/processlist/__init__.py @@ -122,8 +122,8 @@ class ProcesslistPlugin(GlancesPluginModel): stats is a list """ - # The list holds every process on the machine while the UI shows a few dozen rows, and - # the curses output never reads the views at all. Build them on demand. + # Every process on the machine, against a few dozen rows on screen; msg_curse() builds its + # own decorations and never looks at the views. lazy_views = True # Default list of processes stats to be grabbed / displayed diff --git a/tests/test_lazy_views.py b/tests/test_lazy_views.py index bbfcf01b..f5f44fc1 100644 --- a/tests/test_lazy_views.py +++ b/tests/test_lazy_views.py @@ -46,12 +46,6 @@ def test_first_read_builds_the_views(plugin): assert len(views) == 10 -def test_unknown_key_raises(plugin): - plugin.update_views() - with pytest.raises(KeyError): - plugin.get_views(item=999999) - - def test_second_read_reuses_the_built_views(plugin): plugin.update_views() first = plugin.get_views()