diff --git a/src/myfasthtml/controls/Boundaries.py b/src/myfasthtml/controls/Boundaries.py index f82ac89..d85c3c2 100644 --- a/src/myfasthtml/controls/Boundaries.py +++ b/src/myfasthtml/controls/Boundaries.py @@ -26,10 +26,10 @@ class Boundaries(SingleInstance): Keep the boundaries updated """ - def __init__(self, owner, container_id: str = None, on_resize=None, _id=None): - super().__init__(owner, _id=_id) - self._owner = owner - self._container_id = container_id or owner.get_id() + def __init__(self, parent, container_id: str = None, on_resize=None, _id=None): + super().__init__(parent, _id=_id) + self._owner = parent + self._container_id = container_id or parent.get_id() self._on_resize = on_resize self._commands = Commands(self) self._state = BoundariesState() diff --git a/src/myfasthtml/controls/Panel.py b/src/myfasthtml/controls/Panel.py index aa959ee..8223f1b 100644 --- a/src/myfasthtml/controls/Panel.py +++ b/src/myfasthtml/controls/Panel.py @@ -104,7 +104,7 @@ class Panel(MultipleInstance): 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) self.conf = conf or PanelConf() self.commands = Commands(self) diff --git a/src/myfasthtml/controls/Profiler.py b/src/myfasthtml/controls/Profiler.py index 4b87e20..71cb7ae 100644 --- a/src/myfasthtml/controls/Profiler.py +++ b/src/myfasthtml/controls/Profiler.py @@ -161,7 +161,7 @@ class Profiler(SingleInstance): def __init__(self, parent, _id=None): 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._selected_id: str | None = None self._detail_view: str = "tree" diff --git a/src/myfasthtml/core/instances.py b/src/myfasthtml/core/instances.py index 6c4c91f..74774be 100644 --- a/src/myfasthtml/core/instances.py +++ b/src/myfasthtml/core/instances.py @@ -1,3 +1,4 @@ +import inspect import logging import uuid from typing import Optional, Literal @@ -32,9 +33,15 @@ class BaseInstance: if VERBOSE_VERBOSE: 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) - session = args[1] if len(args) > 1 and isinstance(args[1], dict) else kwargs.get("session", None) - _id = args[2] if len(args) > 2 and isinstance(args[2], str) else kwargs.get("_id", None) + sig = inspect.signature(cls.__init__) + bound = sig.bind_partial(None, *args, **kwargs) # None pour 'self' + bound.apply_defaults() + arguments = bound.arguments + + parent = arguments.get("parent", None) + session = arguments.get("session", None) + _id = arguments.get("_id", None) + if VERBOSE_VERBOSE: logger.debug(f" parent={parent}, session={debug_session(session)}, _id={_id}") diff --git a/tests/core/data/conftest.py b/tests/core/data/conftest.py index a36a1ce..a08cc19 100644 --- a/tests/core/data/conftest.py +++ b/tests/core/data/conftest.py @@ -41,4 +41,4 @@ def db_manager(parent): @pytest.fixture def dsm(parent, db_manager): - return DataServicesManager(parent, parent._session) + return DataServicesManager(parent)