Skip to content

Commit e4d78ec

Browse files
committed
Rename ._parent to ._root_session in SessionProxy
Related: #1924 (comment)
1 parent 381e851 commit e4d78ec

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

shiny/express/_stub_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def on_ended(
6666

6767
def make_scope(self, id: Id) -> Session:
6868
ns = self.ns(id)
69-
return SessionProxy(parent=self, ns=ns)
69+
return SessionProxy(root_session=self, ns=ns)
7070

7171
def root_scope(self) -> ExpressStubSession:
7272
return self

shiny/session/_session.py

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ def _process_ui(self, ui: TagChild) -> RenderedDeps:
11651165

11661166
def make_scope(self, id: Id) -> Session:
11671167
ns = self.ns(id)
1168-
return SessionProxy(parent=self, ns=ns)
1168+
return SessionProxy(root_session=self, ns=ns)
11691169

11701170
def root_scope(self) -> AppSession:
11711171
return self
@@ -1200,73 +1200,70 @@ class UpdateProgressMessage(TypedDict):
12001200

12011201

12021202
class SessionProxy(Session):
1203-
def __init__(self, parent: Session, ns: ResolvedId) -> None:
1203+
def __init__(self, root_session: Session, ns: ResolvedId) -> None:
12041204
super().__init__()
12051205

1206-
self._parent = parent
1207-
self.app = parent.app
1208-
self.id = parent.id
1206+
self._root_session = root_session
1207+
self.app = root_session.app
1208+
self.id = root_session.id
12091209
self.ns = ns
1210-
self.input = Inputs(values=parent.input._map, ns=ns)
1210+
self.input = Inputs(values=root_session.input._map, ns=ns)
12111211
self.output = Outputs(
12121212
self,
12131213
ns=ns,
1214-
outputs=parent.output._outputs,
1214+
outputs=root_session.output._outputs,
12151215
)
1216-
self._outbound_message_queues = parent._outbound_message_queues
1217-
self._downloads = parent._downloads
1216+
self._outbound_message_queues = root_session._outbound_message_queues
1217+
self._downloads = root_session._downloads
12181218

12191219
self.bookmark = BookmarkProxy(self)
12201220

12211221
def _is_hidden(self, name: str) -> bool:
1222-
return self._parent._is_hidden(name)
1222+
return self._root_session._is_hidden(name)
12231223

12241224
def on_ended(
12251225
self,
12261226
fn: Callable[[], None] | Callable[[], Awaitable[None]],
12271227
) -> Callable[[], None]:
1228-
return self._parent.on_ended(fn)
1228+
return self._root_session.on_ended(fn)
12291229

12301230
def is_stub_session(self) -> bool:
1231-
return self._parent.is_stub_session()
1231+
return self._root_session.is_stub_session()
12321232

12331233
async def close(self, code: int = 1001) -> None:
1234-
await self._parent.close(code)
1234+
await self._root_session.close(code)
12351235

12361236
def make_scope(self, id: str) -> Session:
1237-
return self._parent.make_scope(self.ns(id))
1237+
return self._root_session.make_scope(self.ns(id))
12381238

12391239
def root_scope(self) -> Session:
1240-
res = self
1241-
while isinstance(res, SessionProxy):
1242-
res = res._parent
1243-
return res
1240+
return self._root_session
12441241

12451242
def _process_ui(self, ui: TagChild) -> RenderedDeps:
1246-
return self._parent._process_ui(ui)
1243+
return self._root_session._process_ui(ui)
12471244

12481245
def send_input_message(self, id: str, message: dict[str, object]) -> None:
1249-
self._parent.send_input_message(self.ns(id), message)
1246+
self._root_session.send_input_message(self.ns(id), message)
12501247

12511248
def _send_insert_ui(
12521249
self, selector: str, multiple: bool, where: str, content: RenderedDeps
12531250
) -> None:
1254-
self._parent._send_insert_ui(selector, multiple, where, content)
1251+
self._root_session._send_insert_ui(selector, multiple, where, content)
12551252

12561253
def _send_remove_ui(self, selector: str, multiple: bool) -> None:
1257-
self._parent._send_remove_ui(selector, multiple)
1254+
self._root_session._send_remove_ui(selector, multiple)
12581255

12591256
def _send_progress(self, type: str, message: object) -> None:
1260-
self._parent._send_progress(type, message) # pyright: ignore
1257+
self._root_session._send_progress(type, message) # pyright: ignore
12611258

12621259
async def send_custom_message(self, type: str, message: dict[str, object]) -> None:
1263-
await self._parent.send_custom_message(type, message)
1260+
await self._root_session.send_custom_message(type, message)
12641261

12651262
def _increment_busy_count(self) -> None:
1266-
self._parent._increment_busy_count()
1263+
self._root_session._increment_busy_count()
12671264

12681265
def _decrement_busy_count(self) -> None:
1269-
self._parent._decrement_busy_count()
1266+
self._root_session._decrement_busy_count()
12701267

12711268
def set_message_handler(
12721269
self,
@@ -1283,7 +1280,7 @@ def set_message_handler(
12831280
if _handler_session is None:
12841281
_handler_session = self
12851282

1286-
return self._parent.set_message_handler(
1283+
return self._root_session.set_message_handler(
12871284
self.ns(name),
12881285
handler,
12891286
_handler_session=_handler_session,
@@ -1294,26 +1291,26 @@ def on_flush(
12941291
fn: Callable[[], None] | Callable[[], Awaitable[None]],
12951292
once: bool = True,
12961293
) -> Callable[[], None]:
1297-
return self._parent.on_flush(fn, once)
1294+
return self._root_session.on_flush(fn, once)
12981295

12991296
async def _send_message(self, message: dict[str, object]) -> None:
1300-
await self._parent._send_message(message)
1297+
await self._root_session._send_message(message)
13011298

13021299
def _send_message_sync(self, message: dict[str, object]) -> None:
1303-
self._parent._send_message_sync(message)
1300+
self._root_session._send_message_sync(message)
13041301

13051302
def on_flushed(
13061303
self,
13071304
fn: Callable[[], None] | Callable[[], Awaitable[None]],
13081305
once: bool = True,
13091306
) -> Callable[[], None]:
1310-
return self._parent.on_flushed(fn, once)
1307+
return self._root_session.on_flushed(fn, once)
13111308

13121309
def dynamic_route(self, name: str, handler: DynamicRouteHandler) -> str:
1313-
return self._parent.dynamic_route(self.ns(name), handler)
1310+
return self._root_session.dynamic_route(self.ns(name), handler)
13141311

13151312
async def _unhandled_error(self, e: Exception) -> None:
1316-
await self._parent._unhandled_error(e)
1313+
await self._root_session._unhandled_error(e)
13171314

13181315
def download(
13191316
self,
@@ -1324,7 +1321,7 @@ def download(
13241321
) -> Callable[[DownloadHandler], None]:
13251322
def wrapper(fn: DownloadHandler):
13261323
id_ = self.ns(id or fn.__name__)
1327-
return self._parent.download(
1324+
return self._root_session.download(
13281325
id=id_,
13291326
filename=filename,
13301327
media_type=media_type,

0 commit comments

Comments
 (0)