Skip to content

Commit 24c134b

Browse files
committed
Move express stub bookmark object
1 parent da07a41 commit 24c134b

File tree

4 files changed

+69
-48
lines changed

4 files changed

+69
-48
lines changed

shiny/bookmark/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
from ._bookmark import Bookmark, BookmarkApp, BookmarkProxy, ShinySaveState
1+
from ._bookmark import (
2+
Bookmark,
3+
BookmarkApp,
4+
BookmarkExpressStub,
5+
BookmarkProxy,
6+
ShinySaveState,
7+
)
28
from ._save_state import SaveState
39

4-
__all__ = ("SaveState", "ShinySaveState", "Bookmark", "BookmarkApp", "BookmarkProxy")
10+
__all__ = (
11+
"SaveState",
12+
"ShinySaveState",
13+
"Bookmark",
14+
"BookmarkApp",
15+
"BookmarkProxy",
16+
"BookmarkExpressStub",
17+
)

shiny/bookmark/_bookmark.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@
5353

5454
if TYPE_CHECKING:
5555
from .._namespaces import ResolvedId
56+
from ..express._stub_session import ExpressStubSession
5657
from ..session import Session
58+
else:
59+
from typing import Any
60+
61+
Session = Any
62+
ResolvedId = Any
63+
ExpressStubSession = Any
64+
5765

5866
BookmarkStore = Literal["url", "server", "disable"]
5967

@@ -406,6 +414,49 @@ def store( # pyright: ignore[reportIncompatibleVariableOverride]
406414
self._root_bookmark.store = value
407415

408416

417+
class BookmarkExpressStub(Bookmark):
418+
419+
def __init__(self, root_session: ExpressStubSession) -> None:
420+
super().__init__(root_session)
421+
self._proxy_exclude_fns = []
422+
423+
def _get_bookmark_exclude(self) -> list[str]:
424+
raise NotImplementedError(
425+
"Please call `._get_bookmark_exclude()` only from a real session object"
426+
)
427+
428+
def on_bookmark(
429+
self,
430+
callback: (
431+
Callable[[ShinySaveState], None]
432+
| Callable[[ShinySaveState], Awaitable[None]]
433+
),
434+
) -> None:
435+
raise NotImplementedError(
436+
"Please call `.on_bookmark()` only from a real session object"
437+
)
438+
439+
def on_bookmarked(
440+
self,
441+
callback: Callable[[str], None] | Callable[[str], Awaitable[None]],
442+
) -> None:
443+
raise NotImplementedError(
444+
"Please call `.on_bookmarked()` only from a real session object"
445+
)
446+
447+
async def update_query_string(
448+
self, query_string: str, mode: Literal["replace", "push"] = "replace"
449+
) -> None:
450+
raise NotImplementedError(
451+
"Please call `.update_query_string()` only from a real session object"
452+
)
453+
454+
async def do_bookmark(self) -> None:
455+
raise NotImplementedError(
456+
"Please call `.do_bookmark()` only from a real session object"
457+
)
458+
459+
409460
# RestoreContext <- R6Class("RestoreContext",
410461
# public = list(
411462
# # This will be set to TRUE if there's actually a state to restore

shiny/bookmark/_save_state.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
if TYPE_CHECKING:
1515
from .. import Inputs
16+
else:
17+
Inputs = Any
1618

1719

1820
class SaveState(ABC):

shiny/express/_stub_session.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
from htmltools import TagChild
66

7-
from shiny.bookmark._bookmark import ShinySaveState
8-
97
from .._namespaces import Id, ResolvedId, Root
8+
from ..bookmark import BookmarkExpressStub
109
from ..session import Inputs, Outputs, Session
11-
from ..session._session import Bookmark, SessionProxy
1210

1311
if TYPE_CHECKING:
1412
from ..session._session import DownloadHandler, DynamicRouteHandler, RenderedDeps
@@ -145,46 +143,3 @@ def download(
145143
encoding: str = "utf-8",
146144
) -> Callable[[DownloadHandler], None]:
147145
return lambda x: None
148-
149-
150-
class BookmarkExpressStub(Bookmark):
151-
152-
def __init__(self, root_session: ExpressStubSession) -> None:
153-
super().__init__(root_session)
154-
self._proxy_exclude_fns = []
155-
156-
def _get_bookmark_exclude(self) -> list[str]:
157-
raise NotImplementedError(
158-
"Please call `._get_bookmark_exclude()` only from a real session object"
159-
)
160-
161-
def on_bookmark(
162-
self,
163-
callback: (
164-
Callable[[ShinySaveState], None]
165-
| Callable[[ShinySaveState], Awaitable[None]]
166-
),
167-
) -> None:
168-
raise NotImplementedError(
169-
"Please call `.on_bookmark()` only from a real session object"
170-
)
171-
172-
def on_bookmarked(
173-
self,
174-
callback: Callable[[str], None] | Callable[[str], Awaitable[None]],
175-
) -> None:
176-
raise NotImplementedError(
177-
"Please call `.on_bookmarked()` only from a real session object"
178-
)
179-
180-
async def update_query_string(
181-
self, query_string: str, mode: Literal["replace", "push"] = "replace"
182-
) -> None:
183-
raise NotImplementedError(
184-
"Please call `.update_query_string()` only from a real session object"
185-
)
186-
187-
async def do_bookmark(self) -> None:
188-
raise NotImplementedError(
189-
"Please call `.do_bookmark()` only from a real session object"
190-
)

0 commit comments

Comments
 (0)