Skip to content

Commit 1cddb17

Browse files
authored
Disable expressify code caching on Pyodide (#1046)
1 parent 9f0e753 commit 1cddb17

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

shiny/express/expressify_decorator/_expressify.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
runtime_checkable,
1818
)
1919

20+
from ..._shinyenv import is_pyodide
2021
from ._func_displayhook import _expressify_decorator_function_def
2122
from ._helpers import find_code_for_func
2223
from ._node_transformers import (
@@ -70,12 +71,18 @@ def decorator(fn: TFunc) -> TFunc:
7071
if hasattr(unwrapped_fn, expressify_attr):
7172
return fn
7273

73-
if unwrapped_fn.__code__ in code_cache:
74-
fcode = code_cache[fn.__code__]
75-
else:
76-
# Save for next time
74+
if is_pyodide:
75+
# Disable code caching on Pyodide due to bug in hashing bytecode in 0.22.1.
76+
# When Pyodide is updated to a newer version, this will be not be needed.
77+
# https://github.com/posit-dev/py-shiny/issues/1042#issuecomment-1901945787
7778
fcode = _transform_body(cast(types.FunctionType, unwrapped_fn))
78-
code_cache[unwrapped_fn.__code__] = fcode
79+
else:
80+
if unwrapped_fn.__code__ in code_cache:
81+
fcode = code_cache[unwrapped_fn.__code__]
82+
else:
83+
# Save for next time
84+
fcode = _transform_body(cast(types.FunctionType, unwrapped_fn))
85+
code_cache[unwrapped_fn.__code__] = fcode
7986

8087
unwrapped_fn.__code__ = fcode
8188
setattr(unwrapped_fn, expressify_attr, True)
@@ -96,12 +103,18 @@ def expressify() -> Callable[[TFunc], TFunc]:
96103

97104
def expressify(fn: TFunc | None = None) -> TFunc | Callable[[TFunc], TFunc]:
98105
def decorator(fn: TFunc) -> TFunc:
99-
if fn.__code__ in code_cache:
100-
fcode = code_cache[fn.__code__]
101-
else:
102-
# Save for next time
106+
if is_pyodide:
107+
# Disable code caching on Pyodide due to bug in hashing bytecode in 0.22.1.
108+
# When Pyodide is updated to a newer version, this will be not be needed.
109+
# https://github.com/posit-dev/py-shiny/issues/1042#issuecomment-1901945787
103110
fcode = _transform_body(cast(types.FunctionType, fn))
104-
code_cache[fn.__code__] = fcode
111+
else:
112+
if fn.__code__ in code_cache:
113+
fcode = code_cache[fn.__code__]
114+
else:
115+
# Save for next time
116+
fcode = _transform_body(cast(types.FunctionType, fn))
117+
code_cache[fn.__code__] = fcode
105118

106119
# Create a new function from the code object
107120
new_func = types.FunctionType(

0 commit comments

Comments
 (0)