We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`CachedStFunctionWarning` incorrectly asks users to set `suppress_st_warning=True` when widget replay is disabled
### Checklist

- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.

### Summary

When you include Streamlit widgets in a cache decorated function, a `CachedStFunctionWarning` is raised because widget replay is disabled by default. That `CachedStFunctionWarning` message asks users to set `suppress_st_warning=True` in the caching decorator to suppress the warning. However, the new cache primitives do not support `suppress_st_warning` as a param.

The warning needs to be edited to replace the mention of `suppress_st_warning` with `experimental_allow_widgets`.

### Reproducible Code Example

```Python
import streamlit as st

@st.cache_resource
def foo():
    st.text_input("foo")

foo()

st.button("Re-run")
```


### Steps To Reproduce

1. Run the app
2. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`
4. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)

### Expected Behavior

1. Run the app
2. Expect to see:
![image](https://user-images.githubusercontent.com/20672874/222661556-d57dc2d1-13f0-41aa-850c-0b273cb1a7d0.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(experimental_allow_widgets=True)`
4. Expect to see:
![image](https://user-images.githubusercontent.com/20672874/222661765-7413e405-b485-4be6-8ba3-8f6a4447c33e.png)


### Current Behavior

1. Run the app
2. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`
4. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)

### Is this a regression?

- [ ] Yes, this used to work in a previous version.

### Debug info

- Streamlit version: 1.19.0
- Python version: 3.9
- Operating System: macOS
- Browser: Chrome
- Virtual environment: None


### Additional Information

_No response_

### Are you willing to submit a PR?

- [X] Yes, I am willing to submit a PR!
`CachedStFunctionWarning` incorrectly asks users to set `suppress_st_warning=True` when widget replay is disabled
### Checklist

- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.

### Summary

When you include Streamlit widgets in a cache decorated function, a `CachedStFunctionWarning` is raised because widget replay is disabled by default. That `CachedStFunctionWarning` message asks users to set `suppress_st_warning=True` in the caching decorator to suppress the warning. However, the new cache primitives do not support `suppress_st_warning` as a param.

The warning needs to be edited to replace the mention of `suppress_st_warning` with `experimental_allow_widgets`.

### Reproducible Code Example

```Python
import streamlit as st

@st.cache_resource
def foo():
    st.text_input("foo")

foo()

st.button("Re-run")
```


### Steps To Reproduce

1. Run the app
2. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`
4. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)

### Expected Behavior

1. Run the app
2. Expect to see:
![image](https://user-images.githubusercontent.com/20672874/222661556-d57dc2d1-13f0-41aa-850c-0b273cb1a7d0.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(experimental_allow_widgets=True)`
4. Expect to see:
![image](https://user-images.githubusercontent.com/20672874/222661765-7413e405-b485-4be6-8ba3-8f6a4447c33e.png)


### Current Behavior

1. Run the app
2. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)
3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`
4. You see the following:
![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)

### Is this a regression?

- [ ] Yes, this used to work in a previous version.

### Debug info

- Streamlit version: 1.19.0
- Python version: 3.9
- Operating System: macOS
- Browser: Chrome
- Virtual environment: None


### Additional Information

_No response_

### Are you willing to submit a PR?

- [X] Yes, I am willing to submit a PR!

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/streamlit/runtime/caching/cache_errors.py`
Content:
```
1 # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import types
16 from typing import Any, Optional
17 
18 from streamlit import type_util
19 from streamlit.errors import (
20     MarkdownFormattedException,
21     StreamlitAPIException,
22     StreamlitAPIWarning,
23 )
24 from streamlit.runtime.caching.cache_type import CacheType, get_decorator_api_name
25 
26 CACHE_DOCS_URL = "https://docs.streamlit.io/library/advanced-features/caching"
27 
28 
29 def get_cached_func_name_md(func: Any) -> str:
30     """Get markdown representation of the function name."""
31     if hasattr(func, "__name__"):
32         return "`%s()`" % func.__name__
33     elif hasattr(type(func), "__name__"):
34         return f"`{type(func).__name__}`"
35     return f"`{type(func)}`"
36 
37 
38 def get_return_value_type(return_value: Any) -> str:
39     if hasattr(return_value, "__module__") and hasattr(type(return_value), "__name__"):
40         return f"`{return_value.__module__}.{type(return_value).__name__}`"
41     return get_cached_func_name_md(return_value)
42 
43 
44 class UnhashableTypeError(Exception):
45     pass
46 
47 
48 class UnhashableParamError(StreamlitAPIException):
49     def __init__(
50         self,
51         cache_type: CacheType,
52         func: types.FunctionType,
53         arg_name: Optional[str],
54         arg_value: Any,
55         orig_exc: BaseException,
56     ):
57         msg = self._create_message(cache_type, func, arg_name, arg_value)
58         super().__init__(msg)
59         self.with_traceback(orig_exc.__traceback__)
60 
61     @staticmethod
62     def _create_message(
63         cache_type: CacheType,
64         func: types.FunctionType,
65         arg_name: Optional[str],
66         arg_value: Any,
67     ) -> str:
68         arg_name_str = arg_name if arg_name is not None else "(unnamed)"
69         arg_type = type_util.get_fqn_type(arg_value)
70         func_name = func.__name__
71         arg_replacement_name = f"_{arg_name}" if arg_name is not None else "_arg"
72 
73         return (
74             f"""
75 Cannot hash argument '{arg_name_str}' (of type `{arg_type}`) in '{func_name}'.
76 
77 To address this, you can tell Streamlit not to hash this argument by adding a
78 leading underscore to the argument's name in the function signature:
79 
80 ```
81 @st.{get_decorator_api_name(cache_type)}
82 def {func_name}({arg_replacement_name}, ...):
83     ...
84 ```
85             """
86         ).strip("\n")
87 
88 
89 class CacheKeyNotFoundError(Exception):
90     pass
91 
92 
93 class CacheError(Exception):
94     pass
95 
96 
97 class CachedStFunctionWarning(StreamlitAPIWarning):
98     def __init__(
99         self,
100         cache_type: CacheType,
101         st_func_name: str,
102         cached_func: types.FunctionType,
103     ):
104         args = {
105             "st_func_name": f"`st.{st_func_name}()`",
106             "func_name": self._get_cached_func_name_md(cached_func),
107             "decorator_name": get_decorator_api_name(cache_type),
108         }
109 
110         msg = (
111             """
112 Your script uses %(st_func_name)s to write to your Streamlit app from within
113 some cached code at %(func_name)s. This code will only be called when we detect
114 a cache "miss", which can lead to unexpected results.
115 
116 How to fix this:
117 * Move the %(st_func_name)s call outside %(func_name)s.
118 * Or, if you know what you're doing, use `@st.%(decorator_name)s(suppress_st_warning=True)`
119 to suppress the warning.
120             """
121             % args
122         ).strip("\n")
123 
124         super().__init__(msg)
125 
126     @staticmethod
127     def _get_cached_func_name_md(func: types.FunctionType) -> str:
128         """Get markdown representation of the function name."""
129         if hasattr(func, "__name__"):
130             return "`%s()`" % func.__name__
131         else:
132             return "a cached function"
133 
134 
135 class CacheReplayClosureError(StreamlitAPIException):
136     def __init__(
137         self,
138         cache_type: CacheType,
139         cached_func: types.FunctionType,
140     ):
141         func_name = get_cached_func_name_md(cached_func)
142         decorator_name = get_decorator_api_name(cache_type)
143 
144         msg = (
145             f"""
146 While running {func_name}, a streamlit element is called on some layout block created outside the function.
147 This is incompatible with replaying the cached effect of that element, because the
148 the referenced block might not exist when the replay happens.
149 
150 How to fix this:
151 * Move the creation of $THING inside {func_name}.
152 * Move the call to the streamlit element outside of {func_name}.
153 * Remove the `@st.{decorator_name}` decorator from {func_name}.
154             """
155         ).strip("\n")
156 
157         super().__init__(msg)
158 
159 
160 class UnserializableReturnValueError(MarkdownFormattedException):
161     def __init__(self, func: types.FunctionType, return_value: types.FunctionType):
162         MarkdownFormattedException.__init__(
163             self,
164             f"""
165             Cannot serialize the return value (of type {get_return_value_type(return_value)}) in {get_cached_func_name_md(func)}.
166             `st.cache_data` uses [pickle](https://docs.python.org/3/library/pickle.html) to
167             serialize the function’s return value and safely store it in the cache without mutating the original object. Please convert the return value to a pickle-serializable type.
168             If you want to cache unserializable objects such as database connections or Tensorflow
169             sessions, use `st.cache_resource` instead (see [our docs]({CACHE_DOCS_URL}) for differences).""",
170         )
171 
172 
173 class UnevaluatedDataFrameError(StreamlitAPIException):
174     """Used to display a message about uncollected dataframe being used"""
175 
176     pass
177
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/streamlit/runtime/caching/cache_errors.py b/lib/streamlit/runtime/caching/cache_errors.py
--- a/lib/streamlit/runtime/caching/cache_errors.py
+++ b/lib/streamlit/runtime/caching/cache_errors.py
@@ -115,8 +115,8 @@
 
 How to fix this:
 * Move the %(st_func_name)s call outside %(func_name)s.
-* Or, if you know what you're doing, use `@st.%(decorator_name)s(suppress_st_warning=True)`
-to suppress the warning.
+* Or, if you know what you're doing, use `@st.%(decorator_name)s(experimental_allow_widgets=True)`
+to enable widget replay and suppress this warning.
             """
             % args
         ).strip("\n")

{"golden_diff": "diff --git a/lib/streamlit/runtime/caching/cache_errors.py b/lib/streamlit/runtime/caching/cache_errors.py\n--- a/lib/streamlit/runtime/caching/cache_errors.py\n+++ b/lib/streamlit/runtime/caching/cache_errors.py\n@@ -115,8 +115,8 @@\n \n How to fix this:\n * Move the %(st_func_name)s call outside %(func_name)s.\n-* Or, if you know what you're doing, use `@st.%(decorator_name)s(suppress_st_warning=True)`\n-to suppress the warning.\n+* Or, if you know what you're doing, use `@st.%(decorator_name)s(experimental_allow_widgets=True)`\n+to enable widget replay and suppress this warning.\n             \"\"\"\n             % args\n         ).strip(\"\\n\")\n", "issue": "`CachedStFunctionWarning` incorrectly asks users to set `suppress_st_warning=True` when widget replay is disabled\n### Checklist\n\n- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.\n- [X] I added a very descriptive title to this issue.\n- [X] I have provided sufficient information below to help reproduce this issue.\n\n### Summary\n\nWhen you include Streamlit widgets in a cache decorated function, a `CachedStFunctionWarning` is raised because widget replay is disabled by default. That `CachedStFunctionWarning` message asks users to set `suppress_st_warning=True` in the caching decorator to suppress the warning. However, the new cache primitives do not support `suppress_st_warning` as a param.\r\n\r\nThe warning needs to be edited to replace the mention of `suppress_st_warning` with `experimental_allow_widgets`.\n\n### Reproducible Code Example\n\n```Python\nimport streamlit as st\r\n\r\n@st.cache_resource\r\ndef foo():\r\n    st.text_input(\"foo\")\r\n\r\nfoo()\r\n\r\nst.button(\"Re-run\")\n```\n\n\n### Steps To Reproduce\n\n1. Run the app\r\n2. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`\r\n4. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)\n\n### Expected Behavior\n\n1. Run the app\r\n2. Expect to see:\r\n![image](https://user-images.githubusercontent.com/20672874/222661556-d57dc2d1-13f0-41aa-850c-0b273cb1a7d0.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(experimental_allow_widgets=True)`\r\n4. Expect to see:\r\n![image](https://user-images.githubusercontent.com/20672874/222661765-7413e405-b485-4be6-8ba3-8f6a4447c33e.png)\r\n\n\n### Current Behavior\n\n1. Run the app\r\n2. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`\r\n4. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)\n\n### Is this a regression?\n\n- [ ] Yes, this used to work in a previous version.\n\n### Debug info\n\n- Streamlit version: 1.19.0\r\n- Python version: 3.9\r\n- Operating System: macOS\r\n- Browser: Chrome\r\n- Virtual environment: None\r\n\n\n### Additional Information\n\n_No response_\n\n### Are you willing to submit a PR?\n\n- [X] Yes, I am willing to submit a PR!\n`CachedStFunctionWarning` incorrectly asks users to set `suppress_st_warning=True` when widget replay is disabled\n### Checklist\n\n- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.\n- [X] I added a very descriptive title to this issue.\n- [X] I have provided sufficient information below to help reproduce this issue.\n\n### Summary\n\nWhen you include Streamlit widgets in a cache decorated function, a `CachedStFunctionWarning` is raised because widget replay is disabled by default. That `CachedStFunctionWarning` message asks users to set `suppress_st_warning=True` in the caching decorator to suppress the warning. However, the new cache primitives do not support `suppress_st_warning` as a param.\r\n\r\nThe warning needs to be edited to replace the mention of `suppress_st_warning` with `experimental_allow_widgets`.\n\n### Reproducible Code Example\n\n```Python\nimport streamlit as st\r\n\r\n@st.cache_resource\r\ndef foo():\r\n    st.text_input(\"foo\")\r\n\r\nfoo()\r\n\r\nst.button(\"Re-run\")\n```\n\n\n### Steps To Reproduce\n\n1. Run the app\r\n2. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`\r\n4. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)\n\n### Expected Behavior\n\n1. Run the app\r\n2. Expect to see:\r\n![image](https://user-images.githubusercontent.com/20672874/222661556-d57dc2d1-13f0-41aa-850c-0b273cb1a7d0.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(experimental_allow_widgets=True)`\r\n4. Expect to see:\r\n![image](https://user-images.githubusercontent.com/20672874/222661765-7413e405-b485-4be6-8ba3-8f6a4447c33e.png)\r\n\n\n### Current Behavior\n\n1. Run the app\r\n2. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222660804-469fca80-34e0-4796-8bae-7e4191e4c153.png)\r\n3. Follow the suggestion and rewrite to `@st.cache_resource(suppress_st_warning=True)`\r\n4. You see the following:\r\n![image](https://user-images.githubusercontent.com/20672874/222661301-8f918598-632c-49a8-a130-18ba2f05cf93.png)\n\n### Is this a regression?\n\n- [ ] Yes, this used to work in a previous version.\n\n### Debug info\n\n- Streamlit version: 1.19.0\r\n- Python version: 3.9\r\n- Operating System: macOS\r\n- Browser: Chrome\r\n- Virtual environment: None\r\n\n\n### Additional Information\n\n_No response_\n\n### Are you willing to submit a PR?\n\n- [X] Yes, I am willing to submit a PR!\n", "before_files": [{"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport types\nfrom typing import Any, Optional\n\nfrom streamlit import type_util\nfrom streamlit.errors import (\n    MarkdownFormattedException,\n    StreamlitAPIException,\n    StreamlitAPIWarning,\n)\nfrom streamlit.runtime.caching.cache_type import CacheType, get_decorator_api_name\n\nCACHE_DOCS_URL = \"https://docs.streamlit.io/library/advanced-features/caching\"\n\n\ndef get_cached_func_name_md(func: Any) -> str:\n    \"\"\"Get markdown representation of the function name.\"\"\"\n    if hasattr(func, \"__name__\"):\n        return \"`%s()`\" % func.__name__\n    elif hasattr(type(func), \"__name__\"):\n        return f\"`{type(func).__name__}`\"\n    return f\"`{type(func)}`\"\n\n\ndef get_return_value_type(return_value: Any) -> str:\n    if hasattr(return_value, \"__module__\") and hasattr(type(return_value), \"__name__\"):\n        return f\"`{return_value.__module__}.{type(return_value).__name__}`\"\n    return get_cached_func_name_md(return_value)\n\n\nclass UnhashableTypeError(Exception):\n    pass\n\n\nclass UnhashableParamError(StreamlitAPIException):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        func: types.FunctionType,\n        arg_name: Optional[str],\n        arg_value: Any,\n        orig_exc: BaseException,\n    ):\n        msg = self._create_message(cache_type, func, arg_name, arg_value)\n        super().__init__(msg)\n        self.with_traceback(orig_exc.__traceback__)\n\n    @staticmethod\n    def _create_message(\n        cache_type: CacheType,\n        func: types.FunctionType,\n        arg_name: Optional[str],\n        arg_value: Any,\n    ) -> str:\n        arg_name_str = arg_name if arg_name is not None else \"(unnamed)\"\n        arg_type = type_util.get_fqn_type(arg_value)\n        func_name = func.__name__\n        arg_replacement_name = f\"_{arg_name}\" if arg_name is not None else \"_arg\"\n\n        return (\n            f\"\"\"\nCannot hash argument '{arg_name_str}' (of type `{arg_type}`) in '{func_name}'.\n\nTo address this, you can tell Streamlit not to hash this argument by adding a\nleading underscore to the argument's name in the function signature:\n\n```\n@st.{get_decorator_api_name(cache_type)}\ndef {func_name}({arg_replacement_name}, ...):\n    ...\n```\n            \"\"\"\n        ).strip(\"\\n\")\n\n\nclass CacheKeyNotFoundError(Exception):\n    pass\n\n\nclass CacheError(Exception):\n    pass\n\n\nclass CachedStFunctionWarning(StreamlitAPIWarning):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        st_func_name: str,\n        cached_func: types.FunctionType,\n    ):\n        args = {\n            \"st_func_name\": f\"`st.{st_func_name}()`\",\n            \"func_name\": self._get_cached_func_name_md(cached_func),\n            \"decorator_name\": get_decorator_api_name(cache_type),\n        }\n\n        msg = (\n            \"\"\"\nYour script uses %(st_func_name)s to write to your Streamlit app from within\nsome cached code at %(func_name)s. This code will only be called when we detect\na cache \"miss\", which can lead to unexpected results.\n\nHow to fix this:\n* Move the %(st_func_name)s call outside %(func_name)s.\n* Or, if you know what you're doing, use `@st.%(decorator_name)s(suppress_st_warning=True)`\nto suppress the warning.\n            \"\"\"\n            % args\n        ).strip(\"\\n\")\n\n        super().__init__(msg)\n\n    @staticmethod\n    def _get_cached_func_name_md(func: types.FunctionType) -> str:\n        \"\"\"Get markdown representation of the function name.\"\"\"\n        if hasattr(func, \"__name__\"):\n            return \"`%s()`\" % func.__name__\n        else:\n            return \"a cached function\"\n\n\nclass CacheReplayClosureError(StreamlitAPIException):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        cached_func: types.FunctionType,\n    ):\n        func_name = get_cached_func_name_md(cached_func)\n        decorator_name = get_decorator_api_name(cache_type)\n\n        msg = (\n            f\"\"\"\nWhile running {func_name}, a streamlit element is called on some layout block created outside the function.\nThis is incompatible with replaying the cached effect of that element, because the\nthe referenced block might not exist when the replay happens.\n\nHow to fix this:\n* Move the creation of $THING inside {func_name}.\n* Move the call to the streamlit element outside of {func_name}.\n* Remove the `@st.{decorator_name}` decorator from {func_name}.\n            \"\"\"\n        ).strip(\"\\n\")\n\n        super().__init__(msg)\n\n\nclass UnserializableReturnValueError(MarkdownFormattedException):\n    def __init__(self, func: types.FunctionType, return_value: types.FunctionType):\n        MarkdownFormattedException.__init__(\n            self,\n            f\"\"\"\n            Cannot serialize the return value (of type {get_return_value_type(return_value)}) in {get_cached_func_name_md(func)}.\n            `st.cache_data` uses [pickle](https://docs.python.org/3/library/pickle.html) to\n            serialize the function\u2019s return value and safely store it in the cache without mutating the original object. Please convert the return value to a pickle-serializable type.\n            If you want to cache unserializable objects such as database connections or Tensorflow\n            sessions, use `st.cache_resource` instead (see [our docs]({CACHE_DOCS_URL}) for differences).\"\"\",\n        )\n\n\nclass UnevaluatedDataFrameError(StreamlitAPIException):\n    \"\"\"Used to display a message about uncollected dataframe being used\"\"\"\n\n    pass\n", "path": "lib/streamlit/runtime/caching/cache_errors.py"}], "after_files": [{"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport types\nfrom typing import Any, Optional\n\nfrom streamlit import type_util\nfrom streamlit.errors import (\n    MarkdownFormattedException,\n    StreamlitAPIException,\n    StreamlitAPIWarning,\n)\nfrom streamlit.runtime.caching.cache_type import CacheType, get_decorator_api_name\n\nCACHE_DOCS_URL = \"https://docs.streamlit.io/library/advanced-features/caching\"\n\n\ndef get_cached_func_name_md(func: Any) -> str:\n    \"\"\"Get markdown representation of the function name.\"\"\"\n    if hasattr(func, \"__name__\"):\n        return \"`%s()`\" % func.__name__\n    elif hasattr(type(func), \"__name__\"):\n        return f\"`{type(func).__name__}`\"\n    return f\"`{type(func)}`\"\n\n\ndef get_return_value_type(return_value: Any) -> str:\n    if hasattr(return_value, \"__module__\") and hasattr(type(return_value), \"__name__\"):\n        return f\"`{return_value.__module__}.{type(return_value).__name__}`\"\n    return get_cached_func_name_md(return_value)\n\n\nclass UnhashableTypeError(Exception):\n    pass\n\n\nclass UnhashableParamError(StreamlitAPIException):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        func: types.FunctionType,\n        arg_name: Optional[str],\n        arg_value: Any,\n        orig_exc: BaseException,\n    ):\n        msg = self._create_message(cache_type, func, arg_name, arg_value)\n        super().__init__(msg)\n        self.with_traceback(orig_exc.__traceback__)\n\n    @staticmethod\n    def _create_message(\n        cache_type: CacheType,\n        func: types.FunctionType,\n        arg_name: Optional[str],\n        arg_value: Any,\n    ) -> str:\n        arg_name_str = arg_name if arg_name is not None else \"(unnamed)\"\n        arg_type = type_util.get_fqn_type(arg_value)\n        func_name = func.__name__\n        arg_replacement_name = f\"_{arg_name}\" if arg_name is not None else \"_arg\"\n\n        return (\n            f\"\"\"\nCannot hash argument '{arg_name_str}' (of type `{arg_type}`) in '{func_name}'.\n\nTo address this, you can tell Streamlit not to hash this argument by adding a\nleading underscore to the argument's name in the function signature:\n\n```\n@st.{get_decorator_api_name(cache_type)}\ndef {func_name}({arg_replacement_name}, ...):\n    ...\n```\n            \"\"\"\n        ).strip(\"\\n\")\n\n\nclass CacheKeyNotFoundError(Exception):\n    pass\n\n\nclass CacheError(Exception):\n    pass\n\n\nclass CachedStFunctionWarning(StreamlitAPIWarning):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        st_func_name: str,\n        cached_func: types.FunctionType,\n    ):\n        args = {\n            \"st_func_name\": f\"`st.{st_func_name}()`\",\n            \"func_name\": self._get_cached_func_name_md(cached_func),\n            \"decorator_name\": get_decorator_api_name(cache_type),\n        }\n\n        msg = (\n            \"\"\"\nYour script uses %(st_func_name)s to write to your Streamlit app from within\nsome cached code at %(func_name)s. This code will only be called when we detect\na cache \"miss\", which can lead to unexpected results.\n\nHow to fix this:\n* Move the %(st_func_name)s call outside %(func_name)s.\n* Or, if you know what you're doing, use `@st.%(decorator_name)s(experimental_allow_widgets=True)`\nto enable widget replay and suppress this warning.\n            \"\"\"\n            % args\n        ).strip(\"\\n\")\n\n        super().__init__(msg)\n\n    @staticmethod\n    def _get_cached_func_name_md(func: types.FunctionType) -> str:\n        \"\"\"Get markdown representation of the function name.\"\"\"\n        if hasattr(func, \"__name__\"):\n            return \"`%s()`\" % func.__name__\n        else:\n            return \"a cached function\"\n\n\nclass CacheReplayClosureError(StreamlitAPIException):\n    def __init__(\n        self,\n        cache_type: CacheType,\n        cached_func: types.FunctionType,\n    ):\n        func_name = get_cached_func_name_md(cached_func)\n        decorator_name = get_decorator_api_name(cache_type)\n\n        msg = (\n            f\"\"\"\nWhile running {func_name}, a streamlit element is called on some layout block created outside the function.\nThis is incompatible with replaying the cached effect of that element, because the\nthe referenced block might not exist when the replay happens.\n\nHow to fix this:\n* Move the creation of $THING inside {func_name}.\n* Move the call to the streamlit element outside of {func_name}.\n* Remove the `@st.{decorator_name}` decorator from {func_name}.\n            \"\"\"\n        ).strip(\"\\n\")\n\n        super().__init__(msg)\n\n\nclass UnserializableReturnValueError(MarkdownFormattedException):\n    def __init__(self, func: types.FunctionType, return_value: types.FunctionType):\n        MarkdownFormattedException.__init__(\n            self,\n            f\"\"\"\n            Cannot serialize the return value (of type {get_return_value_type(return_value)}) in {get_cached_func_name_md(func)}.\n            `st.cache_data` uses [pickle](https://docs.python.org/3/library/pickle.html) to\n            serialize the function\u2019s return value and safely store it in the cache without mutating the original object. Please convert the return value to a pickle-serializable type.\n            If you want to cache unserializable objects such as database connections or Tensorflow\n            sessions, use `st.cache_resource` instead (see [our docs]({CACHE_DOCS_URL}) for differences).\"\"\",\n        )\n\n\nclass UnevaluatedDataFrameError(StreamlitAPIException):\n    \"\"\"Used to display a message about uncollected dataframe being used\"\"\"\n\n    pass\n", "path": "lib/streamlit/runtime/caching/cache_errors.py"}]}