Hardened instance creation

This commit is contained in:
2026-03-23 22:10:11 +01:00
parent 7f099b14f6
commit 3bcf50f55f
5 changed files with 17 additions and 10 deletions

View File

@@ -26,10 +26,10 @@ class Boundaries(SingleInstance):
Keep the boundaries updated Keep the boundaries updated
""" """
def __init__(self, owner, container_id: str = None, on_resize=None, _id=None): def __init__(self, parent, container_id: str = None, on_resize=None, _id=None):
super().__init__(owner, _id=_id) super().__init__(parent, _id=_id)
self._owner = owner self._owner = parent
self._container_id = container_id or owner.get_id() self._container_id = container_id or parent.get_id()
self._on_resize = on_resize self._on_resize = on_resize
self._commands = Commands(self) self._commands = Commands(self)
self._state = BoundariesState() self._state = BoundariesState()

View File

@@ -104,7 +104,7 @@ class Panel(MultipleInstance):
the panel with appropriate HTML elements and JavaScript for interactivity. the panel with appropriate HTML elements and JavaScript for interactivity.
""" """
def __init__(self, parent, conf: Optional[PanelConf] = None, _id=None): def __init__(self, parent, conf: Optional[PanelConf] = None, _id="-panel"):
super().__init__(parent, _id=_id) super().__init__(parent, _id=_id)
self.conf = conf or PanelConf() self.conf = conf or PanelConf()
self.commands = Commands(self) self.commands = Commands(self)

View File

@@ -161,7 +161,7 @@ class Profiler(SingleInstance):
def __init__(self, parent, _id=None): def __init__(self, parent, _id=None):
super().__init__(parent, _id=_id) super().__init__(parent, _id=_id)
self._panel = Panel(self, conf=PanelConf(show_right_title=False, show_display_right=False), _id="-panel") self._panel = Panel(self, conf=PanelConf(show_right_title=False, show_display_right=False))
self._panel.set_side_visible("right", True) self._panel.set_side_visible("right", True)
self._selected_id: str | None = None self._selected_id: str | None = None
self._detail_view: str = "tree" self._detail_view: str = "tree"

View File

@@ -1,3 +1,4 @@
import inspect
import logging import logging
import uuid import uuid
from typing import Optional, Literal from typing import Optional, Literal
@@ -32,9 +33,15 @@ class BaseInstance:
if VERBOSE_VERBOSE: if VERBOSE_VERBOSE:
logger.debug(f"Creating new instance of type {cls.__name__}") logger.debug(f"Creating new instance of type {cls.__name__}")
parent = args[0] if len(args) > 0 and isinstance(args[0], BaseInstance) else kwargs.get("parent", None) sig = inspect.signature(cls.__init__)
session = args[1] if len(args) > 1 and isinstance(args[1], dict) else kwargs.get("session", None) bound = sig.bind_partial(None, *args, **kwargs) # None pour 'self'
_id = args[2] if len(args) > 2 and isinstance(args[2], str) else kwargs.get("_id", None) bound.apply_defaults()
arguments = bound.arguments
parent = arguments.get("parent", None)
session = arguments.get("session", None)
_id = arguments.get("_id", None)
if VERBOSE_VERBOSE: if VERBOSE_VERBOSE:
logger.debug(f" parent={parent}, session={debug_session(session)}, _id={_id}") logger.debug(f" parent={parent}, session={debug_session(session)}, _id={_id}")

View File

@@ -41,4 +41,4 @@ def db_manager(parent):
@pytest.fixture @pytest.fixture
def dsm(parent, db_manager): def dsm(parent, db_manager):
return DataServicesManager(parent, parent._session) return DataServicesManager(parent)