Source code for magicclass.type_matching.list_type

from __future__ import annotations
from typing_extensions import get_args, get_origin
import inspect
from magicgui.type_map import type_matcher
from magicgui.types import WidgetTuple

from ._utils import is_subclass
from ..widgets import ListEdit


[docs]@type_matcher def list_of_any(value, annotation) -> WidgetTuple | None: """Determine if value/annotation is a list[X].""" if annotation and annotation is not inspect.Parameter.empty: orig = get_origin(annotation) args = get_args(annotation) if not (inspect.isclass(orig) and args): return None if is_subclass(orig, list) or isinstance(orig, list): return ListEdit, {} elif value: if isinstance(value, list) and len({type(v) for v in value}) == 1: return ListEdit, {} return None