'TUI adaptions to Client.'
# built-ins
from getpass import getuser
-from dataclasses import asdict as dc_asdict
-from types import get_original_bases
from typing import Any, Callable, Optional, Self, Sequence
# ourselves
from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window,
def __init__(self, path: tuple[str, ...], value: Any) -> None:
self.path = path
- for cls in [cls for cls in _UPDATING_DATACLASSES
- if isinstance(value, get_original_bases(cls)[1])]:
- value = cls(**dc_asdict(value))
self.value = value
+ for cls in [cls for cls in locals().values()
+ if isinstance(cls, type)
+ and issubclass(cls, _UpdatingNode)
+ and cls is not type(value)
+ and issubclass(cls, type(value))]:
+ self.value = cls()
+ self.value.copy_annotated_attrs(value)
@property
def key(self) -> str:
def _make_attr(self, cls: Callable, key: str):
return cls()
+ def copy_annotated_attrs(self, original) -> None:
+ 'From original copy those of its attributes annotated for self.'
+ for key in [k for k in self._deep_annotations()
+ if hasattr(original, k)]:
+ setattr(self, key, getattr(original, key))
+
@classmethod
def _scope(cls, key: str) -> LogScope:
scopes: dict[str, LogScope] = {}