Skip to content

Commit

Permalink
fix: Do not allow for renderer's to be given to reactive effects (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Jan 17, 2024
1 parent 1f77650 commit 68a94da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/cpuinfo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def collect_cpu_samples():
combined_data = combined_data[:, -MAX_SAMPLES:]
cpu_history.set(combined_data)

@reactive.Effect(priority=100)
@reactive.effect(priority=100)
@reactive.event(input.reset)
def reset_history():
cpu_history.set(None)
Expand Down
8 changes: 8 additions & 0 deletions shiny/reactive/_reactives.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ def __init__(
self.__name__ = fn.__name__
self.__doc__ = fn.__doc__

from ..render.renderer import RendererBase

if isinstance(fn, RendererBase):
raise TypeError(
"`@reactive.effect` can not be combined with `@render.xx`.\n"
+ "Please remove your call of `@reactive.effect`."
)

# The EffectAsync subclass will pass in an async function, but it tells the
# static type checker that it's synchronous. wrap_async() is smart -- if is
# passed an async function, it will not change it.
Expand Down
10 changes: 10 additions & 0 deletions tests/pytest/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from shiny import reactive, render
from shiny.render.renderer import Renderer, ValueFn


Expand Down Expand Up @@ -53,3 +54,12 @@ def txt4() -> str:
assert val == "42 42"
val = await txt4.render()
assert val == "42 42 42 42"


def test_effect():
with pytest.raises(TypeError):

@reactive.effect # pyright: ignore[reportGeneralTypeIssues]
@render.text
def my_output():
return "42"

0 comments on commit 68a94da

Please sign in to comment.