Skip to content

Commit 1f0aced

Browse files
committed
Rename suspend_display() to hide()
1 parent a4ab950 commit 1f0aced

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

shiny/express/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from ._is_express import is_express_app
99
from ._output import ( # noqa: F401
1010
ui_kwargs,
11-
suspend_display,
11+
hide,
1212
output_args, # pyright: ignore[reportUnusedImport]
13+
suspend_display, # pyright: ignore[reportUnusedImport] - Deprecated
1314
)
1415
from ._run import wrap_express_app
1516
from .display_decorator import display_body
@@ -20,7 +21,7 @@
2021
"session",
2122
"is_express_app",
2223
"ui_kwargs",
23-
"suspend_display",
24+
"hide",
2425
"wrap_express_app",
2526
"ui",
2627
"display_body",

shiny/express/_output.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from typing import Callable, Generator, TypeVar, overload
77

88
from .. import ui
9+
from .._deprecated import warn_deprecated
910
from .._typing_extensions import ParamSpec
1011
from ..render.renderer import RendererBase, RendererBaseT
1112
from ..render.transformer import OutputRenderer
1213
from ..render.transformer._transformer import OT
1314

1415
__all__ = (
1516
"ui_kwargs",
17+
"hide",
1618
"suspend_display",
1719
)
1820

@@ -98,29 +100,29 @@ def wrapper(renderer: OutputRenderer[OT]) -> OutputRenderer[OT]:
98100

99101

100102
@overload
101-
def suspend_display(fn: CallableT) -> CallableT:
103+
def hide(fn: CallableT) -> CallableT:
102104
...
103105

104106

105107
@overload
106-
def suspend_display(fn: RendererBaseT) -> RendererBaseT:
108+
def hide(fn: RendererBaseT) -> RendererBaseT:
107109
...
108110

109111

110112
@overload
111-
def suspend_display() -> AbstractContextManager[None]:
113+
def hide() -> AbstractContextManager[None]:
112114
...
113115

114116

115-
def suspend_display(
117+
def hide(
116118
fn: Callable[P, R] | RendererBaseT | None = None
117119
) -> Callable[P, R] | RendererBaseT | AbstractContextManager[None]:
118-
"""Suppresses the display of UI elements in various ways.
120+
"""Prevent the display of UI elements in various ways.
119121
120-
If used as a context manager (`with suspend_display():`), it suppresses the display
121-
of all UI elements within the context block. (This is useful when you want to
122-
temporarily suppress the display of a large number of UI elements, or when you want
123-
to suppress the display of UI elements that are not directly under your control.)
122+
If used as a context manager (`with hide():`), it prevents the display of all UI
123+
elements within the context block. (This is useful when you want to temporarily
124+
prevent the display of a large number of UI elements, or when you want to prevent
125+
the display of UI elements that are not directly under your control.)
124126
125127
If used as a decorator (without parentheses) on a Shiny rendering function, it
126128
prevents that function from automatically outputting itself at the point of its
@@ -134,19 +136,19 @@ def suspend_display(
134136
Parameters
135137
----------
136138
fn
137-
The function to decorate. If `None`, returns a context manager that suppresses
138-
the display of UI elements within the context block.
139+
The function to decorate. If `None`, returns a context manager that prevents the
140+
display of UI elements within the context block.
139141
140142
Returns
141143
-------
142144
:
143-
If `fn` is `None`, returns a context manager that suppresses the display of UI
145+
If `fn` is `None`, returns a context manager that prevents the display of UI
144146
elements within the context block. Otherwise, returns a decorated version of
145147
`fn`.
146148
"""
147149

148150
if fn is None:
149-
return suspend_display_ctxmgr()
151+
return hide_ctxmgr()
150152

151153
# Special case for RendererBase; when we decorate those, we just mean "don't
152154
# display yourself"
@@ -155,11 +157,21 @@ def suspend_display(
155157
fn.default_ui = null_ui
156158
return fn
157159

158-
return suspend_display_ctxmgr()(fn)
160+
return hide_ctxmgr()(fn)
161+
162+
163+
def suspend_display(
164+
fn: Callable[P, R] | RendererBaseT | None = None
165+
) -> Callable[P, R] | RendererBaseT | AbstractContextManager[None]:
166+
warn_deprecated(
167+
"`suspend_display` is deprecated. Please use `hide` instead. "
168+
"It has a new name, but the exact same functionality."
169+
)
170+
return hide(fn) # type: ignore
159171

160172

161173
@contextlib.contextmanager
162-
def suspend_display_ctxmgr() -> Generator[None, None, None]:
174+
def hide_ctxmgr() -> Generator[None, None, None]:
163175
oldhook = sys.displayhook
164176
sys.displayhook = null_displayhook
165177
try:

tests/playwright/shiny/shiny-express/suspend_display/app.py renamed to tests/playwright/shiny/shiny-express/hide/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from shiny import render, ui
2-
from shiny.express import input, suspend_display
2+
from shiny.express import hide, input
33

44
with ui.card(id="card"):
55
ui.input_slider("s1", "A", 1, 100, 20)
66

7-
@suspend_display
7+
@hide
88
@render.text
99
def hidden():
1010
return input.s1()

tests/pytest/test_express_ui.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from shiny import render, ui
9-
from shiny.express import suspend_display, ui_kwargs
9+
from shiny.express import hide, ui_kwargs
1010
from shiny.express._run import run_express
1111

1212

@@ -53,7 +53,7 @@ def text1():
5353
== ui.output_text_verbatim("text1").get_html_string()
5454
)
5555

56-
@suspend_display
56+
@hide
5757
@render.text
5858
def text2():
5959
return "text"
@@ -79,7 +79,7 @@ def text4():
7979
text4.tagify()
8080

8181

82-
def test_suspend_display():
82+
def test_hide():
8383
old_displayhook = sys.displayhook
8484
try:
8585
called = False
@@ -90,11 +90,11 @@ def display_hook_spy(_: object) -> Any:
9090

9191
sys.displayhook = display_hook_spy
9292

93-
with suspend_display():
93+
with hide():
9494
sys.displayhook("foo")
95-
suspend_display(lambda: sys.displayhook("bar"))()
95+
hide(lambda: sys.displayhook("bar"))()
9696

97-
@suspend_display
97+
@hide
9898
def whatever(x: Any):
9999
sys.displayhook(x)
100100

0 commit comments

Comments
 (0)