From 6a8dadc2f7ebac1e3aa4783d40c43f7c387c5e6c Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Tue, 28 Oct 2025 03:47:10 +0000 Subject: [PATCH] Optimize _is_viewable_list **Optimizations made:** - Use `type(item_type) is tuple` instead of `isinstance` for a faster type check. - Store `param_list.item_type` to a local variable to avoid repeated attribute lookup. - Replace generator expression in `all()` with an explicit for-loop, which is faster due to avoiding the overhead of a generator and function call. - Behavioral preservation and code style are strictly maintained as requested. --- panel/viewable.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/panel/viewable.py b/panel/viewable.py index 29205b883c..5945778479 100644 --- a/panel/viewable.py +++ b/panel/viewable.py @@ -1242,11 +1242,15 @@ def _is_viewable_class_selector(class_selector: param.ClassSelector) -> bool: return issubclass(class_selector.class_, Viewable) def _is_viewable_list(param_list: param.List) -> bool: - if not param_list.item_type: + item_type = param_list.item_type + if not item_type: return False - if isinstance(param_list.item_type, tuple): - return all(issubclass(cls, Viewable) for cls in param_list.item_type) - return issubclass(param_list.item_type, Viewable) + if type(item_type) is tuple: + for cls in item_type: + if not issubclass(cls, Viewable): + return False + return True + return issubclass(item_type, Viewable) def is_viewable_param(parameter: param.Parameter) -> bool: