streamlit-nightly 1.36.1.dev20240722__py2.py3-none-any.whl → 1.36.1.dev20240724__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,21 +157,25 @@ def make_cached_func_wrapper(info: CachedFuncInfo) -> Callable[..., Any]:
157
157
  some or all of the wrapper's cached values.
158
158
  """
159
159
  cached_func = CachedFunc(info)
160
+ return functools.update_wrapper(cached_func, info.func)
160
161
 
161
- # We'd like to simply return `cached_func`, which is already a Callable.
162
- # But using `functools.update_wrapper` on the CachedFunc instance
163
- # itself results in errors when our caching decorators are used to decorate
164
- # member functions. (See https://github.com/streamlit/streamlit/issues/6109)
165
162
 
166
- @functools.wraps(info.func)
167
- def wrapper(*args, **kwargs):
168
- return cached_func(*args, **kwargs)
163
+ class BoundCachedFunc:
164
+ """A wrapper around a CachedFunc that binds it to a specific instance in case of
165
+ decorated function is a class method."""
169
166
 
170
- # Give our wrapper its `clear` function.
171
- # (This results in a spurious mypy error that we suppress.)
172
- wrapper.clear = cached_func.clear # type: ignore
167
+ def __init__(self, cached_func: CachedFunc, instance: Any):
168
+ self._cached_func = cached_func
169
+ self._instance = instance
173
170
 
174
- return wrapper
171
+ def __call__(self, *args, **kwargs) -> Any:
172
+ return self._cached_func(self._instance, *args, **kwargs)
173
+
174
+ def __repr__(self):
175
+ return f"<BoundCachedFunc: {self._cached_func._info.func} of {self._instance}>"
176
+
177
+ def clear(self, *args, **kwargs):
178
+ self._cached_func.clear(self._instance, *args, **kwargs)
175
179
 
176
180
 
177
181
  class CachedFunc:
@@ -179,6 +183,16 @@ class CachedFunc:
179
183
  self._info = info
180
184
  self._function_key = _make_function_key(info.cache_type, info.func)
181
185
 
186
+ def __repr__(self):
187
+ return f"<CachedFunc: {self._info.func}>"
188
+
189
+ def __get__(self, instance, owner=None):
190
+ """CachedFunc implements descriptor protocol to support cache methods."""
191
+ if instance is None:
192
+ return self
193
+
194
+ return functools.update_wrapper(BoundCachedFunc(self, instance), self)
195
+
182
196
  def __call__(self, *args, **kwargs) -> Any:
183
197
  """The wrapper. We'll only call our underlying function on a cache miss."""
184
198
 
@@ -15,6 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import ast
18
+ import sys
18
19
  from typing import Any, Final
19
20
 
20
21
  from streamlit import config
@@ -46,10 +47,12 @@ def add_magic(code: str, script_path: str) -> Any:
46
47
 
47
48
  file_ends_in_semicolon = _does_file_end_in_semicolon(tree, code)
48
49
 
49
- return _modify_ast_subtree(
50
+ _modify_ast_subtree(
50
51
  tree, is_root=True, file_ends_in_semicolon=file_ends_in_semicolon
51
52
  )
52
53
 
54
+ return tree
55
+
53
56
 
54
57
  def _modify_ast_subtree(
55
58
  tree: Any,
@@ -65,19 +68,25 @@ def _modify_ast_subtree(
65
68
  node_type = type(node)
66
69
 
67
70
  # Recursively parses the content of the statements
68
- # `with`, `for` and `while`, as well as function definitions.
71
+ # `with` as well as function definitions.
69
72
  # Also covers their async counterparts
70
73
  if (
71
74
  node_type is ast.FunctionDef
72
75
  or node_type is ast.With
73
- or node_type is ast.For
74
- or node_type is ast.While
75
76
  or node_type is ast.AsyncFunctionDef
76
77
  or node_type is ast.AsyncWith
77
- or node_type is ast.AsyncFor
78
78
  ):
79
79
  _modify_ast_subtree(node)
80
80
 
81
+ # Recursively parses the content of the statements
82
+ # `for` and `while`.
83
+ # Also covers their async counterparts
84
+ elif (
85
+ node_type is ast.For or node_type is ast.While or node_type is ast.AsyncFor
86
+ ):
87
+ _modify_ast_subtree(node)
88
+ _modify_ast_subtree(node, "orelse")
89
+
81
90
  # Recursively parses methods in a class.
82
91
  elif node_type is ast.ClassDef:
83
92
  for inner_node in node.body:
@@ -86,12 +95,14 @@ def _modify_ast_subtree(
86
95
 
87
96
  # Recursively parses the contents of try statements,
88
97
  # all their handlers (except and else) and the finally body
89
- elif node_type is ast.Try:
90
- for j, inner_node in enumerate(node.handlers):
91
- node.handlers[j] = _modify_ast_subtree(inner_node)
92
- finally_node = _modify_ast_subtree(node, body_attr="finalbody")
93
- node.finalbody = finally_node.finalbody
98
+ elif node_type is ast.Try or (
99
+ sys.version_info >= (3, 11) and node_type is ast.TryStar
100
+ ):
94
101
  _modify_ast_subtree(node)
102
+ _modify_ast_subtree(node, body_attr="finalbody")
103
+ _modify_ast_subtree(node, body_attr="orelse")
104
+ for handler_node in node.handlers:
105
+ _modify_ast_subtree(handler_node)
95
106
 
96
107
  # Recursively parses if blocks, as well as their else/elif blocks
97
108
  # (else/elif are both mapped to orelse)
@@ -100,6 +111,10 @@ def _modify_ast_subtree(
100
111
  _modify_ast_subtree(node)
101
112
  _modify_ast_subtree(node, "orelse")
102
113
 
114
+ elif sys.version_info >= (3, 10) and node_type is ast.Match:
115
+ for case_node in node.cases:
116
+ _modify_ast_subtree(case_node)
117
+
103
118
  # Convert standalone expression nodes to st.write
104
119
  elif node_type is ast.Expr:
105
120
  value = _get_st_write_from_expr(
@@ -119,8 +134,6 @@ def _modify_ast_subtree(
119
134
 
120
135
  ast.fix_missing_locations(tree)
121
136
 
122
- return tree
123
-
124
137
 
125
138
  def _insert_import_statement(tree: Any) -> None:
126
139
  """Insert Streamlit import statement at the top(ish) of the tree."""
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.29bca1b5.css",
4
- "main.js": "./static/js/main.35bc5645.js",
4
+ "main.js": "./static/js/main.94c2fada.js",
5
5
  "static/js/9336.3e046ad7.chunk.js": "./static/js/9336.3e046ad7.chunk.js",
6
6
  "static/js/9330.2b4c99e0.chunk.js": "./static/js/9330.2b4c99e0.chunk.js",
7
7
  "static/js/2736.7d516fcc.chunk.js": "./static/js/2736.7d516fcc.chunk.js",
@@ -152,6 +152,6 @@
152
152
  },
153
153
  "entrypoints": [
154
154
  "static/css/main.29bca1b5.css",
155
- "static/js/main.35bc5645.js"
155
+ "static/js/main.94c2fada.js"
156
156
  ]
157
157
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.35bc5645.js"></script><link href="./static/css/main.29bca1b5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.94c2fada.js"></script><link href="./static/css/main.29bca1b5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>