streamlit-nightly 1.31.2.dev20240212__py2.py3-none-any.whl → 1.31.2.dev20240214__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.
Files changed (184) hide show
  1. streamlit/case_converters.py +9 -4
  2. streamlit/cli_util.py +2 -0
  3. streamlit/code_util.py +5 -2
  4. streamlit/color_util.py +2 -0
  5. streamlit/column_config.py +2 -0
  6. streamlit/commands/execution_control.py +4 -2
  7. streamlit/commands/experimental_query_params.py +7 -4
  8. streamlit/commands/page_config.py +11 -9
  9. streamlit/components/v1/components.py +23 -16
  10. streamlit/config.py +3 -5
  11. streamlit/config_option.py +12 -11
  12. streamlit/connections/base_connection.py +4 -2
  13. streamlit/connections/snowflake_connection.py +4 -4
  14. streamlit/connections/snowpark_connection.py +3 -3
  15. streamlit/connections/sql_connection.py +6 -6
  16. streamlit/connections/util.py +8 -5
  17. streamlit/constants.py +2 -0
  18. streamlit/cursor.py +16 -14
  19. streamlit/delta_generator.py +10 -13
  20. streamlit/deprecation_util.py +4 -3
  21. streamlit/echo.py +5 -3
  22. streamlit/elements/alert.py +16 -14
  23. streamlit/elements/altair_utils.py +8 -6
  24. streamlit/elements/arrow.py +4 -4
  25. streamlit/elements/arrow_altair.py +24 -34
  26. streamlit/elements/arrow_vega_lite.py +9 -14
  27. streamlit/elements/balloons.py +4 -2
  28. streamlit/elements/bokeh_chart.py +7 -7
  29. streamlit/elements/code.py +6 -4
  30. streamlit/elements/deck_gl_json_chart.py +8 -8
  31. streamlit/elements/doc_string.py +5 -9
  32. streamlit/elements/empty.py +4 -2
  33. streamlit/elements/exception.py +10 -10
  34. streamlit/elements/form.py +1 -3
  35. streamlit/elements/graphviz_chart.py +5 -6
  36. streamlit/elements/heading.py +16 -14
  37. streamlit/elements/iframe.py +14 -12
  38. streamlit/elements/image.py +8 -8
  39. streamlit/elements/json.py +6 -4
  40. streamlit/elements/layouts.py +12 -10
  41. streamlit/elements/lib/column_config_utils.py +2 -2
  42. streamlit/elements/lib/column_types.py +23 -23
  43. streamlit/elements/lib/dicttools.py +10 -6
  44. streamlit/elements/lib/mutable_status_container.py +7 -7
  45. streamlit/elements/lib/pandas_styler_utils.py +6 -6
  46. streamlit/elements/lib/streamlit_plotly_theme.py +2 -0
  47. streamlit/elements/map.py +11 -22
  48. streamlit/elements/markdown.py +16 -14
  49. streamlit/elements/media.py +16 -16
  50. streamlit/elements/metric.py +9 -7
  51. streamlit/elements/plotly_chart.py +5 -5
  52. streamlit/elements/progress.py +6 -6
  53. streamlit/elements/pyplot.py +10 -13
  54. streamlit/elements/snow.py +4 -2
  55. streamlit/elements/spinner.py +2 -0
  56. streamlit/elements/text.py +7 -5
  57. streamlit/elements/toast.py +6 -4
  58. streamlit/elements/utils.py +15 -28
  59. streamlit/elements/widgets/button.py +39 -39
  60. streamlit/elements/widgets/camera_input.py +21 -17
  61. streamlit/elements/widgets/chat.py +6 -7
  62. streamlit/elements/widgets/checkbox.py +21 -19
  63. streamlit/elements/widgets/color_picker.py +18 -16
  64. streamlit/elements/widgets/data_editor.py +7 -7
  65. streamlit/elements/widgets/file_uploader.py +59 -55
  66. streamlit/elements/widgets/multiselect.py +33 -42
  67. streamlit/elements/widgets/number_input.py +10 -5
  68. streamlit/elements/widgets/radio.py +1 -1
  69. streamlit/elements/widgets/select_slider.py +25 -34
  70. streamlit/elements/widgets/selectbox.py +1 -1
  71. streamlit/elements/widgets/slider.py +28 -36
  72. streamlit/elements/widgets/text_widgets.py +6 -6
  73. streamlit/elements/widgets/time_widgets.py +13 -13
  74. streamlit/elements/write.py +21 -29
  75. streamlit/env_util.py +5 -3
  76. streamlit/error_util.py +7 -3
  77. streamlit/errors.py +3 -1
  78. streamlit/external/langchain/streamlit_callback_handler.py +26 -24
  79. streamlit/file_util.py +18 -14
  80. streamlit/folder_black_list.py +3 -1
  81. streamlit/git_util.py +5 -3
  82. streamlit/js_number.py +10 -13
  83. streamlit/logger.py +5 -5
  84. streamlit/net_util.py +14 -11
  85. streamlit/platform.py +2 -0
  86. streamlit/runtime/__init__.py +2 -0
  87. streamlit/runtime/app_session.py +42 -42
  88. streamlit/runtime/caching/__init__.py +4 -4
  89. streamlit/runtime/caching/cache_data_api.py +3 -3
  90. streamlit/runtime/caching/cache_errors.py +5 -3
  91. streamlit/runtime/caching/cache_type.py +2 -0
  92. streamlit/runtime/caching/cache_utils.py +2 -4
  93. streamlit/runtime/caching/cached_message_replay.py +12 -5
  94. streamlit/runtime/caching/hashing.py +29 -21
  95. streamlit/runtime/caching/storage/cache_storage_protocol.py +1 -2
  96. streamlit/runtime/caching/storage/local_disk_cache_storage.py +6 -5
  97. streamlit/runtime/connection_factory.py +8 -8
  98. streamlit/runtime/forward_msg_cache.py +20 -18
  99. streamlit/runtime/forward_msg_queue.py +8 -9
  100. streamlit/runtime/legacy_caching/caching.py +32 -42
  101. streamlit/runtime/legacy_caching/hashing.py +29 -25
  102. streamlit/runtime/media_file_manager.py +16 -14
  103. streamlit/runtime/media_file_storage.py +8 -8
  104. streamlit/runtime/memory_media_file_storage.py +12 -14
  105. streamlit/runtime/memory_session_storage.py +4 -3
  106. streamlit/runtime/memory_uploaded_file_manager.py +9 -10
  107. streamlit/runtime/metrics_util.py +20 -20
  108. streamlit/runtime/runtime.py +25 -27
  109. streamlit/runtime/runtime_util.py +5 -3
  110. streamlit/runtime/script_data.py +2 -0
  111. streamlit/runtime/scriptrunner/magic.py +17 -11
  112. streamlit/runtime/scriptrunner/magic_funcs.py +2 -0
  113. streamlit/runtime/scriptrunner/script_requests.py +6 -4
  114. streamlit/runtime/scriptrunner/script_run_context.py +17 -17
  115. streamlit/runtime/scriptrunner/script_runner.py +7 -5
  116. streamlit/runtime/secrets.py +4 -6
  117. streamlit/runtime/session_manager.py +14 -14
  118. streamlit/runtime/state/common.py +5 -4
  119. streamlit/runtime/state/query_params.py +8 -6
  120. streamlit/runtime/state/query_params_proxy.py +7 -5
  121. streamlit/runtime/state/safe_session_state.py +7 -5
  122. streamlit/runtime/state/session_state.py +3 -4
  123. streamlit/runtime/state/session_state_proxy.py +5 -5
  124. streamlit/runtime/state/widgets.py +20 -18
  125. streamlit/runtime/stats.py +13 -15
  126. streamlit/runtime/uploaded_file_manager.py +6 -5
  127. streamlit/runtime/websocket_session_manager.py +14 -14
  128. streamlit/source_util.py +13 -11
  129. streamlit/static/asset-manifest.json +13 -13
  130. streamlit/static/index.html +1 -1
  131. streamlit/static/static/css/2411.8b8f33d6.chunk.css +1 -0
  132. streamlit/static/static/css/43.e3b876c5.chunk.css +1 -0
  133. streamlit/static/static/css/6692.65519639.chunk.css +1 -0
  134. streamlit/static/static/js/{3075.76725a14.chunk.js → 2411.714d213e.chunk.js} +2 -2
  135. streamlit/static/static/js/4185.21ca0590.chunk.js +1 -0
  136. streamlit/static/static/js/43.36939bb1.chunk.js +1 -0
  137. streamlit/static/static/js/{5117.6a701db1.chunk.js → 5117.04bfe5d3.chunk.js} +1 -1
  138. streamlit/static/static/js/{5791.30b01ee8.chunk.js → 5791.c5138157.chunk.js} +1 -1
  139. streamlit/static/static/js/656.8c998bc8.chunk.js +2 -0
  140. streamlit/static/static/js/{6692.6ac4ea6f.chunk.js → 6692.6496cbc2.chunk.js} +1 -1
  141. streamlit/static/static/js/7142.400eefdd.chunk.js +1 -0
  142. streamlit/static/static/js/main.2737c0f9.js +2 -0
  143. streamlit/static/static/js/{main.043d802e.js.LICENSE.txt → main.2737c0f9.js.LICENSE.txt} +23 -25
  144. streamlit/string_util.py +13 -9
  145. streamlit/temporary_directory.py +3 -1
  146. streamlit/testing/v1/element_tree.py +1 -2
  147. streamlit/testing/v1/util.py +7 -3
  148. streamlit/type_util.py +30 -25
  149. streamlit/url_util.py +6 -4
  150. streamlit/user_info.py +8 -6
  151. streamlit/util.py +23 -37
  152. streamlit/version.py +16 -9
  153. streamlit/watcher/event_based_path_watcher.py +10 -10
  154. streamlit/watcher/local_sources_watcher.py +15 -13
  155. streamlit/watcher/path_watcher.py +0 -3
  156. streamlit/watcher/polling_path_watcher.py +9 -8
  157. streamlit/watcher/util.py +3 -2
  158. streamlit/web/cache_storage_manager_config.py +2 -0
  159. streamlit/web/server/app_static_file_handler.py +6 -5
  160. streamlit/web/server/browser_websocket_handler.py +10 -8
  161. streamlit/web/server/component_request_handler.py +7 -4
  162. streamlit/web/server/media_file_handler.py +5 -4
  163. streamlit/web/server/routes.py +6 -3
  164. streamlit/web/server/server.py +41 -34
  165. streamlit/web/server/server_util.py +8 -3
  166. streamlit/web/server/stats_request_handler.py +14 -5
  167. streamlit/web/server/upload_file_request_handler.py +7 -8
  168. streamlit/web/server/websocket_headers.py +2 -2
  169. {streamlit_nightly-1.31.2.dev20240212.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/METADATA +1 -1
  170. {streamlit_nightly-1.31.2.dev20240212.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/RECORD +176 -176
  171. streamlit/static/static/css/3075.81b3d18f.chunk.css +0 -1
  172. streamlit/static/static/css/43.c24b25fa.chunk.css +0 -1
  173. streamlit/static/static/css/6692.bb444a79.chunk.css +0 -1
  174. streamlit/static/static/js/1215.baf3721f.chunk.js +0 -2
  175. streamlit/static/static/js/4185.90e929dc.chunk.js +0 -1
  176. streamlit/static/static/js/43.8ca4bc8a.chunk.js +0 -1
  177. streamlit/static/static/js/7142.a359ed63.chunk.js +0 -1
  178. streamlit/static/static/js/main.043d802e.js +0 -2
  179. /streamlit/static/static/js/{3075.76725a14.chunk.js.LICENSE.txt → 2411.714d213e.chunk.js.LICENSE.txt} +0 -0
  180. /streamlit/static/static/js/{1215.baf3721f.chunk.js.LICENSE.txt → 656.8c998bc8.chunk.js.LICENSE.txt} +0 -0
  181. {streamlit_nightly-1.31.2.dev20240212.data → streamlit_nightly-1.31.2.dev20240214.data}/scripts/streamlit.cmd +0 -0
  182. {streamlit_nightly-1.31.2.dev20240212.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/WHEEL +0 -0
  183. {streamlit_nightly-1.31.2.dev20240212.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/entry_points.txt +0 -0
  184. {streamlit_nightly-1.31.2.dev20240212.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/top_level.txt +0 -0
@@ -14,15 +14,14 @@
14
14
 
15
15
  """Streamlit support for Matplotlib PyPlot charts."""
16
16
 
17
- import io
18
- from typing import TYPE_CHECKING, Any, Optional, cast
17
+ from __future__ import annotations
19
18
 
20
- from typing_extensions import Final
19
+ import io
20
+ from typing import TYPE_CHECKING, Any, cast
21
21
 
22
22
  import streamlit.elements.image as image_utils
23
23
  from streamlit import config
24
24
  from streamlit.errors import StreamlitDeprecationWarning
25
- from streamlit.logger import get_logger
26
25
  from streamlit.proto.Image_pb2 import ImageList as ImageListProto
27
26
  from streamlit.runtime.metrics_util import gather_metrics
28
27
 
@@ -31,18 +30,16 @@ if TYPE_CHECKING:
31
30
 
32
31
  from streamlit.delta_generator import DeltaGenerator
33
32
 
34
- LOGGER: Final = get_logger(__name__)
35
-
36
33
 
37
34
  class PyplotMixin:
38
35
  @gather_metrics("pyplot")
39
36
  def pyplot(
40
37
  self,
41
- fig: Optional["Figure"] = None,
42
- clear_figure: Optional[bool] = None,
38
+ fig: Figure | None = None,
39
+ clear_figure: bool | None = None,
43
40
  use_container_width: bool = True,
44
41
  **kwargs: Any,
45
- ) -> "DeltaGenerator":
42
+ ) -> DeltaGenerator:
46
43
  """Display a matplotlib.pyplot figure.
47
44
 
48
45
  Parameters
@@ -117,7 +114,7 @@ class PyplotMixin:
117
114
  return self.dg._enqueue("imgs", image_list_proto)
118
115
 
119
116
  @property
120
- def dg(self) -> "DeltaGenerator":
117
+ def dg(self) -> DeltaGenerator:
121
118
  """Get our DeltaGenerator."""
122
119
  return cast("DeltaGenerator", self)
123
120
 
@@ -125,8 +122,8 @@ class PyplotMixin:
125
122
  def marshall(
126
123
  coordinates: str,
127
124
  image_list_proto: ImageListProto,
128
- fig: Optional["Figure"] = None,
129
- clear_figure: Optional[bool] = True,
125
+ fig: Figure | None = None,
126
+ clear_figure: bool | None = True,
130
127
  use_container_width: bool = True,
131
128
  **kwargs: Any,
132
129
  ) -> None:
@@ -183,7 +180,7 @@ def marshall(
183
180
 
184
181
  class PyplotGlobalUseWarning(StreamlitDeprecationWarning):
185
182
  def __init__(self) -> None:
186
- super(PyplotGlobalUseWarning, self).__init__(
183
+ super().__init__(
187
184
  msg=self._get_message(), config_option="deprecation.showPyplotGlobalUse"
188
185
  )
189
186
 
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from typing import TYPE_CHECKING, cast
16
18
 
17
19
  from streamlit.proto.Snow_pb2 import Snow as SnowProto
@@ -23,7 +25,7 @@ if TYPE_CHECKING:
23
25
 
24
26
  class SnowMixin:
25
27
  @gather_metrics("snow")
26
- def snow(self) -> "DeltaGenerator":
28
+ def snow(self) -> DeltaGenerator:
27
29
  """Draw celebratory snowfall.
28
30
 
29
31
  Example
@@ -40,6 +42,6 @@ class SnowMixin:
40
42
  return self.dg._enqueue("snow", snow_proto)
41
43
 
42
44
  @property
43
- def dg(self) -> "DeltaGenerator":
45
+ def dg(self) -> DeltaGenerator:
44
46
  """Get our DeltaGenerator."""
45
47
  return cast("DeltaGenerator", self)
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  import contextlib
16
18
  import threading
17
19
  from typing import Iterator
@@ -12,7 +12,9 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import TYPE_CHECKING, Optional, cast
15
+ from __future__ import annotations
16
+
17
+ from typing import TYPE_CHECKING, cast
16
18
 
17
19
  from streamlit.proto.Text_pb2 import Text as TextProto
18
20
  from streamlit.runtime.metrics_util import gather_metrics
@@ -27,10 +29,10 @@ class TextMixin:
27
29
  @gather_metrics("text")
28
30
  def text(
29
31
  self,
30
- body: "SupportsStr",
32
+ body: SupportsStr,
31
33
  *, # keyword-only arguments:
32
- help: Optional[str] = None,
33
- ) -> "DeltaGenerator":
34
+ help: str | None = None,
35
+ ) -> DeltaGenerator:
34
36
  """Write fixed-width and preformatted text.
35
37
 
36
38
  Parameters
@@ -55,6 +57,6 @@ class TextMixin:
55
57
  return self.dg._enqueue("text", text_proto)
56
58
 
57
59
  @property
58
- def dg(self) -> "DeltaGenerator":
60
+ def dg(self) -> DeltaGenerator:
59
61
  """Get our DeltaGenerator."""
60
62
  return cast("DeltaGenerator", self)
@@ -12,7 +12,9 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import TYPE_CHECKING, Optional, cast
15
+ from __future__ import annotations
16
+
17
+ from typing import TYPE_CHECKING, cast
16
18
 
17
19
  from streamlit.errors import StreamlitAPIException
18
20
  from streamlit.proto.Toast_pb2 import Toast as ToastProto
@@ -39,8 +41,8 @@ class ToastMixin:
39
41
  self,
40
42
  body: SupportsStr,
41
43
  *, # keyword-only args:
42
- icon: Optional[str] = None,
43
- ) -> "DeltaGenerator":
44
+ icon: str | None = None,
45
+ ) -> DeltaGenerator:
44
46
  """Display a short message, known as a notification "toast".
45
47
  The toast appears in the app's bottom-right corner and disappears after four seconds.
46
48
 
@@ -86,6 +88,6 @@ class ToastMixin:
86
88
  return self.dg._enqueue("toast", toast_proto)
87
89
 
88
90
  @property
89
- def dg(self) -> "DeltaGenerator":
91
+ def dg(self) -> DeltaGenerator:
90
92
  """Get our DeltaGenerator."""
91
93
  return cast("DeltaGenerator", self)
@@ -12,21 +12,10 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from enum import Enum, EnumMeta
16
- from typing import (
17
- TYPE_CHECKING,
18
- Any,
19
- Hashable,
20
- Iterable,
21
- List,
22
- Optional,
23
- Sequence,
24
- Tuple,
25
- Type,
26
- Union,
27
- cast,
28
- overload,
29
- )
18
+ from typing import TYPE_CHECKING, Any, Hashable, Iterable, Sequence, cast, overload
30
19
 
31
20
  import streamlit
32
21
  from streamlit import config, runtime, type_util
@@ -43,8 +32,8 @@ if TYPE_CHECKING:
43
32
 
44
33
 
45
34
  def last_index_for_melted_dataframes(
46
- data: Union["DataFrameCompatible", Any]
47
- ) -> Optional[Hashable]:
35
+ data: DataFrameCompatible | Any,
36
+ ) -> Hashable | None:
48
37
  if type_util.is_dataframe_compatible(data):
49
38
  data = type_util.convert_anything_to_df(data)
50
39
 
@@ -54,9 +43,7 @@ def last_index_for_melted_dataframes(
54
43
  return None
55
44
 
56
45
 
57
- def check_callback_rules(
58
- dg: "DeltaGenerator", on_change: Optional[WidgetCallback]
59
- ) -> None:
46
+ def check_callback_rules(dg: DeltaGenerator, on_change: WidgetCallback | None) -> None:
60
47
  if runtime.exists() and is_in_form(dg) and on_change is not None:
61
48
  raise StreamlitAPIException(
62
49
  "With forms, callbacks can only be defined on the `st.form_submit_button`."
@@ -73,7 +60,7 @@ st.chat_input, and st.form cannot be set using st.session_state.
73
60
 
74
61
 
75
62
  def check_session_state_rules(
76
- default_value: Any, key: Optional[str], writes_allowed: bool = True
63
+ default_value: Any, key: str | None, writes_allowed: bool = True
77
64
  ) -> None:
78
65
  global _shown_default_value_warning
79
66
 
@@ -101,7 +88,7 @@ def check_session_state_rules(
101
88
 
102
89
  def get_label_visibility_proto_value(
103
90
  label_visibility_string: type_util.LabelVisibility,
104
- ) -> "LabelVisibilityMessage.LabelVisibilityOptions.ValueType":
91
+ ) -> LabelVisibilityMessage.LabelVisibilityOptions.ValueType:
105
92
  """Returns one of LabelVisibilityMessage enum constants.py based on string value."""
106
93
 
107
94
  if label_visibility_string == "visible":
@@ -117,7 +104,7 @@ def get_label_visibility_proto_value(
117
104
  @overload
118
105
  def maybe_coerce_enum(
119
106
  register_widget_result: RegisterWidgetResult[Enum],
120
- options: Type[Enum],
107
+ options: type[Enum],
121
108
  opt_sequence: Sequence[Any],
122
109
  ) -> RegisterWidgetResult[Enum]:
123
110
  ...
@@ -141,7 +128,7 @@ def maybe_coerce_enum(register_widget_result, options, opt_sequence):
141
128
  if not isinstance(register_widget_result.value, Enum):
142
129
  return register_widget_result
143
130
 
144
- coerce_class: Optional[EnumMeta]
131
+ coerce_class: EnumMeta | None
145
132
  if isinstance(options, EnumMeta):
146
133
  coerce_class = options
147
134
  else:
@@ -159,19 +146,19 @@ def maybe_coerce_enum(register_widget_result, options, opt_sequence):
159
146
  # (https://github.com/python/typing/issues/548)
160
147
  @overload
161
148
  def maybe_coerce_enum_sequence(
162
- register_widget_result: RegisterWidgetResult[List[T]],
149
+ register_widget_result: RegisterWidgetResult[list[T]],
163
150
  options: type_util.OptionSequence[T],
164
151
  opt_sequence: Sequence[T],
165
- ) -> RegisterWidgetResult[List[T]]:
152
+ ) -> RegisterWidgetResult[list[T]]:
166
153
  ...
167
154
 
168
155
 
169
156
  @overload
170
157
  def maybe_coerce_enum_sequence(
171
- register_widget_result: RegisterWidgetResult[Tuple[T, T]],
158
+ register_widget_result: RegisterWidgetResult[tuple[T, T]],
172
159
  options: type_util.OptionSequence[T],
173
160
  opt_sequence: Sequence[T],
174
- ) -> RegisterWidgetResult[Tuple[T, T]]:
161
+ ) -> RegisterWidgetResult[tuple[T, T]]:
175
162
  ...
176
163
 
177
164
 
@@ -185,7 +172,7 @@ def maybe_coerce_enum_sequence(register_widget_result, options, opt_sequence):
185
172
  return register_widget_result
186
173
 
187
174
  # Extract the class to coerce
188
- coerce_class: Optional[EnumMeta]
175
+ coerce_class: EnumMeta | None
189
176
  if isinstance(options, EnumMeta):
190
177
  coerce_class = options
191
178
  else:
@@ -18,9 +18,9 @@ import io
18
18
  import os
19
19
  from dataclasses import dataclass
20
20
  from textwrap import dedent
21
- from typing import TYPE_CHECKING, BinaryIO, Optional, TextIO, Union, cast
21
+ from typing import TYPE_CHECKING, BinaryIO, Final, Literal, TextIO, Union, cast
22
22
 
23
- from typing_extensions import Final, Literal
23
+ from typing_extensions import TypeAlias
24
24
 
25
25
  from streamlit import runtime, source_util
26
26
  from streamlit.elements.form import current_form_id, is_in_form
@@ -52,7 +52,7 @@ For more information, refer to the
52
52
  [documentation for forms](https://docs.streamlit.io/library/api-reference/control-flow/st.form).
53
53
  """
54
54
 
55
- DownloadButtonDataType = Union[str, bytes, TextIO, BinaryIO, io.RawIOBase]
55
+ DownloadButtonDataType: TypeAlias = Union[str, bytes, TextIO, BinaryIO, io.RawIOBase]
56
56
 
57
57
 
58
58
  @dataclass
@@ -60,7 +60,7 @@ class ButtonSerde:
60
60
  def serialize(self, v: bool) -> bool:
61
61
  return bool(v)
62
62
 
63
- def deserialize(self, ui_value: Optional[bool], widget_id: str = "") -> bool:
63
+ def deserialize(self, ui_value: bool | None, widget_id: str = "") -> bool:
64
64
  return ui_value or False
65
65
 
66
66
 
@@ -69,11 +69,11 @@ class ButtonMixin:
69
69
  def button(
70
70
  self,
71
71
  label: str,
72
- key: Optional[Key] = None,
73
- help: Optional[str] = None,
74
- on_click: Optional[WidgetCallback] = None,
75
- args: Optional[WidgetArgs] = None,
76
- kwargs: Optional[WidgetKwargs] = None,
72
+ key: Key | None = None,
73
+ help: str | None = None,
74
+ on_click: WidgetCallback | None = None,
75
+ args: WidgetArgs | None = None,
76
+ kwargs: WidgetKwargs | None = None,
77
77
  *, # keyword-only arguments:
78
78
  type: Literal["primary", "secondary"] = "secondary",
79
79
  disabled: bool = False,
@@ -179,13 +179,13 @@ class ButtonMixin:
179
179
  self,
180
180
  label: str,
181
181
  data: DownloadButtonDataType,
182
- file_name: Optional[str] = None,
183
- mime: Optional[str] = None,
184
- key: Optional[Key] = None,
185
- help: Optional[str] = None,
186
- on_click: Optional[WidgetCallback] = None,
187
- args: Optional[WidgetArgs] = None,
188
- kwargs: Optional[WidgetKwargs] = None,
182
+ file_name: str | None = None,
183
+ mime: str | None = None,
184
+ key: Key | None = None,
185
+ help: str | None = None,
186
+ on_click: WidgetCallback | None = None,
187
+ args: WidgetArgs | None = None,
188
+ kwargs: WidgetKwargs | None = None,
189
189
  *, # keyword-only arguments:
190
190
  type: Literal["primary", "secondary"] = "secondary",
191
191
  disabled: bool = False,
@@ -350,11 +350,11 @@ class ButtonMixin:
350
350
  label: str,
351
351
  url: str,
352
352
  *,
353
- help: Optional[str] = None,
353
+ help: str | None = None,
354
354
  type: Literal["primary", "secondary"] = "secondary",
355
355
  disabled: bool = False,
356
356
  use_container_width: bool = False,
357
- ) -> "DeltaGenerator":
357
+ ) -> DeltaGenerator:
358
358
  r"""Display a link button element.
359
359
 
360
360
  When clicked, a new tab will be opened to the specified URL. This will
@@ -437,7 +437,7 @@ class ButtonMixin:
437
437
  help: str | None = None,
438
438
  disabled: bool = False,
439
439
  use_container_width: bool | None = None,
440
- ) -> "DeltaGenerator":
440
+ ) -> DeltaGenerator:
441
441
  """Display a link to another page in a multipage app or to an external page.
442
442
 
443
443
  If another page in a multipage app is specified, clicking ``st.page_link``
@@ -537,18 +537,18 @@ class ButtonMixin:
537
537
  self,
538
538
  label: str,
539
539
  data: DownloadButtonDataType,
540
- file_name: Optional[str] = None,
541
- mime: Optional[str] = None,
542
- key: Optional[Key] = None,
543
- help: Optional[str] = None,
544
- on_click: Optional[WidgetCallback] = None,
545
- args: Optional[WidgetArgs] = None,
546
- kwargs: Optional[WidgetKwargs] = None,
540
+ file_name: str | None = None,
541
+ mime: str | None = None,
542
+ key: Key | None = None,
543
+ help: str | None = None,
544
+ on_click: WidgetCallback | None = None,
545
+ args: WidgetArgs | None = None,
546
+ kwargs: WidgetKwargs | None = None,
547
547
  *, # keyword-only arguments:
548
548
  type: Literal["primary", "secondary"] = "secondary",
549
549
  disabled: bool = False,
550
550
  use_container_width: bool = False,
551
- ctx: Optional[ScriptRunContext] = None,
551
+ ctx: ScriptRunContext | None = None,
552
552
  ) -> bool:
553
553
  key = to_key(key)
554
554
  check_session_state_rules(default_value=None, key=key, writes_allowed=False)
@@ -606,12 +606,12 @@ class ButtonMixin:
606
606
  self,
607
607
  label: str,
608
608
  url: str,
609
- help: Optional[str],
609
+ help: str | None,
610
610
  *, # keyword-only arguments:
611
611
  type: Literal["primary", "secondary"] = "secondary",
612
612
  disabled: bool = False,
613
613
  use_container_width: bool = False,
614
- ) -> "DeltaGenerator":
614
+ ) -> DeltaGenerator:
615
615
  link_button_proto = LinkButtonProto()
616
616
  link_button_proto.label = label
617
617
  link_button_proto.url = url
@@ -633,7 +633,7 @@ class ButtonMixin:
633
633
  help: str | None = None,
634
634
  disabled: bool = False,
635
635
  use_container_width: bool | None = None,
636
- ) -> "DeltaGenerator":
636
+ ) -> DeltaGenerator:
637
637
  page_link_proto = PageLinkProto()
638
638
  page_link_proto.disabled = disabled
639
639
 
@@ -692,17 +692,17 @@ class ButtonMixin:
692
692
  def _button(
693
693
  self,
694
694
  label: str,
695
- key: Optional[str],
696
- help: Optional[str],
695
+ key: str | None,
696
+ help: str | None,
697
697
  is_form_submitter: bool,
698
- on_click: Optional[WidgetCallback] = None,
699
- args: Optional[WidgetArgs] = None,
700
- kwargs: Optional[WidgetKwargs] = None,
698
+ on_click: WidgetCallback | None = None,
699
+ args: WidgetArgs | None = None,
700
+ kwargs: WidgetKwargs | None = None,
701
701
  *, # keyword-only arguments:
702
702
  type: Literal["primary", "secondary"] = "secondary",
703
703
  disabled: bool = False,
704
704
  use_container_width: bool = False,
705
- ctx: Optional[ScriptRunContext] = None,
705
+ ctx: ScriptRunContext | None = None,
706
706
  ) -> bool:
707
707
  if not is_form_submitter:
708
708
  check_callback_rules(self.dg, on_click)
@@ -767,7 +767,7 @@ class ButtonMixin:
767
767
  return button_state.value
768
768
 
769
769
  @property
770
- def dg(self) -> "DeltaGenerator":
770
+ def dg(self) -> DeltaGenerator:
771
771
  """Get our DeltaGenerator."""
772
772
  return cast("DeltaGenerator", self)
773
773
 
@@ -776,8 +776,8 @@ def marshall_file(
776
776
  coordinates: str,
777
777
  data: DownloadButtonDataType,
778
778
  proto_download_button: DownloadButtonProto,
779
- mimetype: Optional[str],
780
- file_name: Optional[str] = None,
779
+ mimetype: str | None,
780
+ file_name: str | None = None,
781
781
  ) -> None:
782
782
  data_as_bytes: bytes
783
783
  if isinstance(data, str):
@@ -12,9 +12,13 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from dataclasses import dataclass
16
18
  from textwrap import dedent
17
- from typing import TYPE_CHECKING, Optional, Union, cast
19
+ from typing import TYPE_CHECKING, Union, cast
20
+
21
+ from typing_extensions import TypeAlias
18
22
 
19
23
  from streamlit.elements.form import current_form_id
20
24
  from streamlit.elements.utils import (
@@ -41,7 +45,7 @@ from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings
41
45
  if TYPE_CHECKING:
42
46
  from streamlit.delta_generator import DeltaGenerator
43
47
 
44
- SomeUploadedSnapshotFile = Union[UploadedFile, DeletedFile, None]
48
+ SomeUploadedSnapshotFile: TypeAlias = Union[UploadedFile, DeletedFile, None]
45
49
 
46
50
 
47
51
  @dataclass
@@ -64,7 +68,7 @@ class CameraInputSerde:
64
68
  return state_proto
65
69
 
66
70
  def deserialize(
67
- self, ui_value: Optional[FileUploaderStateProto], widget_id: str
71
+ self, ui_value: FileUploaderStateProto | None, widget_id: str
68
72
  ) -> SomeUploadedSnapshotFile:
69
73
  upload_files = _get_upload_files(ui_value)
70
74
  if len(upload_files) == 0:
@@ -79,15 +83,15 @@ class CameraInputMixin:
79
83
  def camera_input(
80
84
  self,
81
85
  label: str,
82
- key: Optional[Key] = None,
83
- help: Optional[str] = None,
84
- on_change: Optional[WidgetCallback] = None,
85
- args: Optional[WidgetArgs] = None,
86
- kwargs: Optional[WidgetKwargs] = None,
86
+ key: Key | None = None,
87
+ help: str | None = None,
88
+ on_change: WidgetCallback | None = None,
89
+ args: WidgetArgs | None = None,
90
+ kwargs: WidgetKwargs | None = None,
87
91
  *, # keyword-only arguments:
88
92
  disabled: bool = False,
89
93
  label_visibility: LabelVisibility = "visible",
90
- ) -> Optional[UploadedFile]:
94
+ ) -> UploadedFile | None:
91
95
  r"""Display a widget that returns pictures from the user's webcam.
92
96
 
93
97
  Parameters
@@ -180,16 +184,16 @@ class CameraInputMixin:
180
184
  def _camera_input(
181
185
  self,
182
186
  label: str,
183
- key: Optional[Key] = None,
184
- help: Optional[str] = None,
185
- on_change: Optional[WidgetCallback] = None,
186
- args: Optional[WidgetArgs] = None,
187
- kwargs: Optional[WidgetKwargs] = None,
187
+ key: Key | None = None,
188
+ help: str | None = None,
189
+ on_change: WidgetCallback | None = None,
190
+ args: WidgetArgs | None = None,
191
+ kwargs: WidgetKwargs | None = None,
188
192
  *, # keyword-only arguments:
189
193
  disabled: bool = False,
190
194
  label_visibility: LabelVisibility = "visible",
191
- ctx: Optional[ScriptRunContext] = None,
192
- ) -> Optional[UploadedFile]:
195
+ ctx: ScriptRunContext | None = None,
196
+ ) -> UploadedFile | None:
193
197
  key = to_key(key)
194
198
  check_callback_rules(self.dg, on_change)
195
199
  check_session_state_rules(default_value=None, key=key, writes_allowed=False)
@@ -238,6 +242,6 @@ class CameraInputMixin:
238
242
  return camera_input_state.value
239
243
 
240
244
  @property
241
- def dg(self) -> "DeltaGenerator":
245
+ def dg(self) -> DeltaGenerator:
242
246
  """Get our DeltaGenerator."""
243
247
  return cast("DeltaGenerator", self)
@@ -11,13 +11,12 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
+
14
15
  from __future__ import annotations
15
16
 
16
17
  from dataclasses import dataclass
17
18
  from enum import Enum
18
- from typing import TYPE_CHECKING, Optional, Tuple, cast
19
-
20
- from typing_extensions import Literal
19
+ from typing import TYPE_CHECKING, Literal, cast
21
20
 
22
21
  from streamlit import runtime
23
22
  from streamlit.elements.form import is_in_form
@@ -53,7 +52,7 @@ class PresetNames(str, Enum):
53
52
 
54
53
  def _process_avatar_input(
55
54
  avatar: str | AtomicImage | None, delta_path: str
56
- ) -> Tuple[BlockProto.ChatMessage.AvatarType.ValueType, str]:
55
+ ) -> tuple[BlockProto.ChatMessage.AvatarType.ValueType, str]:
57
56
  """Detects the avatar type and prepares the avatar data for the frontend.
58
57
 
59
58
  Parameters
@@ -102,7 +101,7 @@ def _process_avatar_input(
102
101
  @dataclass
103
102
  class ChatInputSerde:
104
103
  def deserialize(
105
- self, ui_value: Optional[StringTriggerValueProto], widget_id: str = ""
104
+ self, ui_value: StringTriggerValueProto | None, widget_id: str = ""
106
105
  ) -> str | None:
107
106
  if ui_value is None or not ui_value.HasField("data"):
108
107
  return None
@@ -120,7 +119,7 @@ class ChatMixin:
120
119
  name: Literal["user", "assistant", "ai", "human"] | str,
121
120
  *,
122
121
  avatar: Literal["user", "assistant"] | str | AtomicImage | None = None,
123
- ) -> "DeltaGenerator":
122
+ ) -> DeltaGenerator:
124
123
  """Insert a chat message container.
125
124
 
126
125
  To add elements to the returned container, you can use ``with`` notation
@@ -366,6 +365,6 @@ class ChatMixin:
366
365
  return widget_state.value if not widget_state.value_changed else None
367
366
 
368
367
  @property
369
- def dg(self) -> "DeltaGenerator":
368
+ def dg(self) -> DeltaGenerator:
370
369
  """Get our DeltaGenerator."""
371
370
  return cast("DeltaGenerator", self)