17
17
runtime_checkable ,
18
18
)
19
19
20
+ from ..._shinyenv import is_pyodide
20
21
from ._func_displayhook import _expressify_decorator_function_def
21
22
from ._helpers import find_code_for_func
22
23
from ._node_transformers import (
@@ -70,12 +71,18 @@ def decorator(fn: TFunc) -> TFunc:
70
71
if hasattr (unwrapped_fn , expressify_attr ):
71
72
return fn
72
73
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
77
78
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
79
86
80
87
unwrapped_fn .__code__ = fcode
81
88
setattr (unwrapped_fn , expressify_attr , True )
@@ -96,12 +103,18 @@ def expressify() -> Callable[[TFunc], TFunc]:
96
103
97
104
def expressify (fn : TFunc | None = None ) -> TFunc | Callable [[TFunc ], TFunc ]:
98
105
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
103
110
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
105
118
106
119
# Create a new function from the code object
107
120
new_func = types .FunctionType (
0 commit comments