? why do we care if it's None

pull/35543/head
Shane Smiskol 2 months ago
parent 4d36b1233f
commit e5293c3f48
  1. 10
      system/ui/lib/widget.py

@ -2,7 +2,7 @@ import abc
import pyray as rl import pyray as rl
from enum import IntEnum from enum import IntEnum
from collections.abc import Callable from collections.abc import Callable
from typing import TypeVar, cast from typing import TypeVar
class DialogResult(IntEnum): class DialogResult(IntEnum):
@ -14,10 +14,8 @@ class DialogResult(IntEnum):
T = TypeVar("T") T = TypeVar("T")
def _resolve_value(value: T | Callable[[], T], default: T | str = "") -> T: def _resolve_value(value: T | Callable[[], T]) -> T:
if callable(value): return value() if callable(value) else value
return value()
return value if value is not None else cast(T, default)
class Widget(abc.ABC): class Widget(abc.ABC):
@ -28,7 +26,7 @@ class Widget(abc.ABC):
@property @property
def is_visible(self) -> bool: def is_visible(self) -> bool:
return _resolve_value(self._is_visible, True) return _resolve_value(self._is_visible)
def set_visible(self, visible: bool | Callable[[], bool]) -> None: def set_visible(self, visible: bool | Callable[[], bool]) -> None:
self._is_visible = visible self._is_visible = visible

Loading…
Cancel
Save