3
3
import warnings
4
4
from abc import ABC , abstractmethod
5
5
from pathlib import Path
6
- from typing import TYPE_CHECKING , Awaitable , Callable , Literal
6
+ from typing import TYPE_CHECKING , Awaitable , Callable , Literal , Optional
7
7
8
8
from .._docstring import add_example
9
9
from .._utils import AsyncCallbacks , CancelCallback , wrap_async
@@ -167,7 +167,7 @@ def on_restored(
167
167
@abstractmethod
168
168
async def update_query_string (
169
169
self ,
170
- query_string : str ,
170
+ query_string : Optional [ str ] = None ,
171
171
mode : Literal ["replace" , "push" ] = "replace" ,
172
172
) -> None :
173
173
"""
@@ -176,7 +176,7 @@ async def update_query_string(
176
176
Parameters
177
177
----------
178
178
query_string
179
- The query string to set.
179
+ The query string to set. If `None`, the current bookmark state URL will be used.
180
180
mode
181
181
Whether to replace the current URL or push a new one. Pushing a new value
182
182
will add to the user's browser history.
@@ -448,9 +448,12 @@ async def invoke_on_restored_callbacks():
448
448
449
449
async def update_query_string (
450
450
self ,
451
- query_string : str ,
451
+ query_string : Optional [ str ] = None ,
452
452
mode : Literal ["replace" , "push" ] = "replace" ,
453
453
) -> None :
454
+ if query_string is None :
455
+ query_string = await self .get_bookmark_url ()
456
+
454
457
if mode not in {"replace" , "push" }:
455
458
raise ValueError (f"Invalid mode: { mode } " )
456
459
await self ._root_session ._send_message (
@@ -723,7 +726,9 @@ def _restore_context(self) -> RestoreContext | None:
723
726
return self ._root_bookmark ._restore_context
724
727
725
728
async def update_query_string (
726
- self , query_string : str , mode : Literal ["replace" , "push" ] = "replace"
729
+ self ,
730
+ query_string : Optional [str ] = None ,
731
+ mode : Literal ["replace" , "push" ] = "replace" ,
727
732
) -> None :
728
733
await self ._root_bookmark .update_query_string (query_string , mode )
729
734
@@ -769,7 +774,9 @@ def on_bookmarked(
769
774
return lambda : None
770
775
771
776
async def update_query_string (
772
- self , query_string : str , mode : Literal ["replace" , "push" ] = "replace"
777
+ self ,
778
+ query_string : Optional [str ] = None ,
779
+ mode : Literal ["replace" , "push" ] = "replace" ,
773
780
) -> None :
774
781
# no-op within ExpressStub
775
782
return None
0 commit comments