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,11 +14,11 @@
14
14
 
15
15
  """A Python wrapper around Bokeh."""
16
16
 
17
+ from __future__ import annotations
18
+
17
19
  import hashlib
18
20
  import json
19
- from typing import TYPE_CHECKING, cast
20
-
21
- from typing_extensions import Final
21
+ from typing import TYPE_CHECKING, Final, cast
22
22
 
23
23
  from streamlit.errors import StreamlitAPIException
24
24
  from streamlit.proto.BokehChart_pb2 import BokehChart as BokehChartProto
@@ -37,9 +37,9 @@ class BokehMixin:
37
37
  @gather_metrics("bokeh_chart")
38
38
  def bokeh_chart(
39
39
  self,
40
- figure: "Figure",
40
+ figure: Figure,
41
41
  use_container_width: bool = False,
42
- ) -> "DeltaGenerator":
42
+ ) -> DeltaGenerator:
43
43
  """Display an interactive Bokeh chart.
44
44
 
45
45
  Bokeh is a charting library for Python. The arguments to this function
@@ -99,14 +99,14 @@ class BokehMixin:
99
99
  return self.dg._enqueue("bokeh_chart", bokeh_chart_proto)
100
100
 
101
101
  @property
102
- def dg(self) -> "DeltaGenerator":
102
+ def dg(self) -> DeltaGenerator:
103
103
  """Get our DeltaGenerator."""
104
104
  return cast("DeltaGenerator", self)
105
105
 
106
106
 
107
107
  def marshall(
108
108
  proto: BokehChartProto,
109
- figure: "Figure",
109
+ figure: Figure,
110
110
  use_container_width: bool,
111
111
  element_id: str,
112
112
  ) -> None:
@@ -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.Code_pb2 import Code as CodeProto
18
20
  from streamlit.runtime.metrics_util import gather_metrics
@@ -28,9 +30,9 @@ class CodeMixin:
28
30
  def code(
29
31
  self,
30
32
  body: SupportsStr,
31
- language: Optional[str] = "python",
33
+ language: str | None = "python",
32
34
  line_numbers: bool = False,
33
- ) -> "DeltaGenerator":
35
+ ) -> DeltaGenerator:
34
36
  """Display a code block with optional syntax highlighting.
35
37
 
36
38
  Parameters
@@ -66,6 +68,6 @@ class CodeMixin:
66
68
  return self.dg._enqueue("code", code_proto)
67
69
 
68
70
  @property
69
- def dg(self) -> "DeltaGenerator":
71
+ def dg(self) -> DeltaGenerator:
70
72
  """Get our DeltaGenerator."""
71
73
  return cast("DeltaGenerator", self)
@@ -12,11 +12,11 @@
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 hashlib
16
18
  import json
17
- from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, cast
18
-
19
- from typing_extensions import Final
19
+ from typing import TYPE_CHECKING, Any, Final, Mapping, cast
20
20
 
21
21
  from streamlit import config
22
22
  from streamlit.proto.DeckGlJsonChart_pb2 import DeckGlJsonChart as PydeckProto
@@ -39,9 +39,9 @@ class PydeckMixin:
39
39
  @gather_metrics("pydeck_chart")
40
40
  def pydeck_chart(
41
41
  self,
42
- pydeck_obj: Optional["Deck"] = None,
42
+ pydeck_obj: Deck | None = None,
43
43
  use_container_width: bool = False,
44
- ) -> "DeltaGenerator":
44
+ ) -> DeltaGenerator:
45
45
  """Draw a chart using the PyDeck library.
46
46
 
47
47
  This supports 3D maps, point clouds, and more! More info about PyDeck
@@ -131,12 +131,12 @@ class PydeckMixin:
131
131
  return self.dg._enqueue("deck_gl_json_chart", pydeck_proto)
132
132
 
133
133
  @property
134
- def dg(self) -> "DeltaGenerator":
134
+ def dg(self) -> DeltaGenerator:
135
135
  """Get our DeltaGenerator."""
136
136
  return cast("DeltaGenerator", self)
137
137
 
138
138
 
139
- def _get_pydeck_tooltip(pydeck_obj: Optional["Deck"]) -> Optional[Dict[str, str]]:
139
+ def _get_pydeck_tooltip(pydeck_obj: Deck | None) -> dict[str, str] | None:
140
140
  if pydeck_obj is None:
141
141
  return None
142
142
 
@@ -156,7 +156,7 @@ def _get_pydeck_tooltip(pydeck_obj: Optional["Deck"]) -> Optional[Dict[str, str]
156
156
 
157
157
  def marshall(
158
158
  pydeck_proto: PydeckProto,
159
- pydeck_obj: Optional["Deck"],
159
+ pydeck_obj: Deck | None,
160
160
  use_container_width: bool,
161
161
  ) -> None:
162
162
  if pydeck_obj is None:
@@ -14,17 +14,16 @@
14
14
 
15
15
  """Allows us to create and absorb changes (aka Deltas) to elements."""
16
16
 
17
+ from __future__ import annotations
18
+
17
19
  import ast
18
20
  import contextlib
19
21
  import inspect
20
22
  import re
21
23
  import types
22
- from typing import TYPE_CHECKING, Any, cast
23
-
24
- from typing_extensions import Final
24
+ from typing import TYPE_CHECKING, Any, Final, cast
25
25
 
26
26
  import streamlit
27
- from streamlit.logger import get_logger
28
27
  from streamlit.proto.DocString_pb2 import DocString as DocStringProto
29
28
  from streamlit.proto.DocString_pb2 import Member as MemberProto
30
29
  from streamlit.runtime.metrics_util import gather_metrics
@@ -38,15 +37,12 @@ if TYPE_CHECKING:
38
37
  from streamlit.delta_generator import DeltaGenerator
39
38
 
40
39
 
41
- LOGGER: Final = get_logger(__name__)
42
-
43
-
44
40
  CONFUSING_STREAMLIT_SIG_PREFIXES: Final = ("(element, ",)
45
41
 
46
42
 
47
43
  class HelpMixin:
48
44
  @gather_metrics("help")
49
- def help(self, obj: Any = streamlit) -> "DeltaGenerator":
45
+ def help(self, obj: Any = streamlit) -> DeltaGenerator:
50
46
  """Display help and other information for a given object.
51
47
 
52
48
  Depending on the type of object that is passed in, this displays the
@@ -123,7 +119,7 @@ class HelpMixin:
123
119
  return self.dg._enqueue("doc_string", doc_string_proto)
124
120
 
125
121
  @property
126
- def dg(self) -> "DeltaGenerator":
122
+ def dg(self) -> DeltaGenerator:
127
123
  """Get our DeltaGenerator."""
128
124
  return cast("DeltaGenerator", self)
129
125
 
@@ -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.Empty_pb2 import Empty as EmptyProto
@@ -21,7 +23,7 @@ if TYPE_CHECKING:
21
23
 
22
24
 
23
25
  class EmptyMixin:
24
- def empty(self) -> "DeltaGenerator":
26
+ def empty(self) -> DeltaGenerator:
25
27
  """Insert a single-element container.
26
28
 
27
29
  Inserts a container into your app that can be used to hold a single element.
@@ -70,6 +72,6 @@ class EmptyMixin:
70
72
  return self.dg._enqueue("empty", empty_proto)
71
73
 
72
74
  @property
73
- def dg(self) -> "DeltaGenerator":
75
+ def dg(self) -> DeltaGenerator:
74
76
  """Get our DeltaGenerator."""
75
77
  return cast("DeltaGenerator", self)
@@ -12,11 +12,11 @@
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 os
16
18
  import traceback
17
- from typing import TYPE_CHECKING, List, Optional, cast
18
-
19
- from typing_extensions import Final
19
+ from typing import TYPE_CHECKING, Final, cast
20
20
 
21
21
  import streamlit
22
22
  from streamlit.errors import (
@@ -33,7 +33,7 @@ from streamlit.runtime.metrics_util import gather_metrics
33
33
  if TYPE_CHECKING:
34
34
  from streamlit.delta_generator import DeltaGenerator
35
35
 
36
- LOGGER: Final = get_logger(__name__)
36
+ _LOGGER: Final = get_logger(__name__)
37
37
 
38
38
  # When client.showErrorDetails is False, we show a generic warning in the
39
39
  # frontend when we encounter an uncaught app exception.
@@ -48,7 +48,7 @@ _STREAMLIT_DIR: Final = os.path.join(
48
48
 
49
49
  class ExceptionMixin:
50
50
  @gather_metrics("exception")
51
- def exception(self, exception: BaseException) -> "DeltaGenerator":
51
+ def exception(self, exception: BaseException) -> DeltaGenerator:
52
52
  """Display an exception.
53
53
 
54
54
  Parameters
@@ -69,7 +69,7 @@ class ExceptionMixin:
69
69
  return self.dg._enqueue("exception", exception_proto)
70
70
 
71
71
  @property
72
- def dg(self) -> "DeltaGenerator":
72
+ def dg(self) -> DeltaGenerator:
73
73
  """Get our DeltaGenerator."""
74
74
  return cast("DeltaGenerator", self)
75
75
 
@@ -124,7 +124,7 @@ def marshall(exception_proto: ExceptionProto, exception: BaseException) -> None:
124
124
  # Sometimes the exception's __str__/__unicode__ method itself
125
125
  # raises an error.
126
126
  exception_proto.message = ""
127
- LOGGER.warning(
127
+ _LOGGER.warning(
128
128
  """
129
129
 
130
130
  Streamlit was unable to parse the data from an exception in the user's script.
@@ -193,7 +193,7 @@ def _format_syntax_error_message(exception: SyntaxError) -> str:
193
193
 
194
194
  def _get_stack_trace_str_list(
195
195
  exception: BaseException, strip_streamlit_stack_entries: bool = False
196
- ) -> List[str]:
196
+ ) -> list[str]:
197
197
  """Get the stack trace for the given exception.
198
198
 
199
199
  Parameters
@@ -213,7 +213,7 @@ def _get_stack_trace_str_list(
213
213
  The exception traceback as a list of strings
214
214
 
215
215
  """
216
- extracted_traceback: Optional[traceback.StackSummary] = None
216
+ extracted_traceback: traceback.StackSummary | None = None
217
217
  if isinstance(exception, StreamlitAPIWarning):
218
218
  extracted_traceback = exception.tacked_on_stack
219
219
  elif hasattr(exception, "__traceback__"):
@@ -253,7 +253,7 @@ def _is_in_streamlit_package(file: str) -> bool:
253
253
 
254
254
  def _get_nonstreamlit_traceback(
255
255
  extracted_tb: traceback.StackSummary,
256
- ) -> List[traceback.FrameSummary]:
256
+ ) -> list[traceback.FrameSummary]:
257
257
  return [
258
258
  entry for entry in extracted_tb if not _is_in_streamlit_package(entry.filename)
259
259
  ]
@@ -14,9 +14,7 @@
14
14
  from __future__ import annotations
15
15
 
16
16
  import textwrap
17
- from typing import TYPE_CHECKING, NamedTuple, cast
18
-
19
- from typing_extensions import Literal
17
+ from typing import TYPE_CHECKING, Literal, NamedTuple, cast
20
18
 
21
19
  from streamlit import runtime
22
20
  from streamlit.errors import StreamlitAPIException
@@ -14,14 +14,15 @@
14
14
 
15
15
  """Streamlit support for GraphViz charts."""
16
16
 
17
+ from __future__ import annotations
18
+
17
19
  import hashlib
18
20
  from typing import TYPE_CHECKING, Union, cast
19
21
 
20
- from typing_extensions import Final, TypeAlias
22
+ from typing_extensions import TypeAlias
21
23
 
22
24
  from streamlit import type_util
23
25
  from streamlit.errors import StreamlitAPIException
24
- from streamlit.logger import get_logger
25
26
  from streamlit.proto.GraphVizChart_pb2 import GraphVizChart as GraphVizChartProto
26
27
  from streamlit.runtime.metrics_util import gather_metrics
27
28
  from streamlit.util import HASHLIB_KWARGS
@@ -31,8 +32,6 @@ if TYPE_CHECKING:
31
32
 
32
33
  from streamlit.delta_generator import DeltaGenerator
33
34
 
34
- LOGGER: Final = get_logger(__name__)
35
-
36
35
  FigureOrDot: TypeAlias = Union["graphviz.Graph", "graphviz.Digraph", str]
37
36
 
38
37
 
@@ -42,7 +41,7 @@ class GraphvizMixin:
42
41
  self,
43
42
  figure_or_dot: FigureOrDot,
44
43
  use_container_width: bool = False,
45
- ) -> "DeltaGenerator":
44
+ ) -> DeltaGenerator:
46
45
  """Display a graph using the dagre-d3 library.
47
46
 
48
47
  Parameters
@@ -113,7 +112,7 @@ class GraphvizMixin:
113
112
  return self.dg._enqueue("graphviz_chart", graphviz_chart_proto)
114
113
 
115
114
  @property
116
- def dg(self) -> "DeltaGenerator":
115
+ def dg(self) -> DeltaGenerator:
117
116
  """Get our DeltaGenerator."""
118
117
  return cast("DeltaGenerator", self)
119
118
 
@@ -12,10 +12,12 @@
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
16
- from typing import TYPE_CHECKING, Optional, Union, cast
18
+ from typing import TYPE_CHECKING, Literal, Union, cast
17
19
 
18
- from typing_extensions import Literal
20
+ from typing_extensions import TypeAlias
19
21
 
20
22
  from streamlit.errors import StreamlitAPIException
21
23
  from streamlit.proto.Heading_pb2 import Heading as HeadingProto
@@ -33,8 +35,8 @@ class HeadingProtoTag(Enum):
33
35
  SUBHEADER_TAG = "h3"
34
36
 
35
37
 
36
- Anchor = Optional[Union[str, Literal[False]]]
37
- Divider = Optional[Union[bool, str]]
38
+ Anchor: TypeAlias = Union[str, Literal[False], None]
39
+ Divider: TypeAlias = Union[bool, str, None]
38
40
 
39
41
 
40
42
  class HeadingMixin:
@@ -44,9 +46,9 @@ class HeadingMixin:
44
46
  body: SupportsStr,
45
47
  anchor: Anchor = None,
46
48
  *, # keyword-only arguments:
47
- help: Optional[str] = None,
49
+ help: str | None = None,
48
50
  divider: Divider = False,
49
- ) -> "DeltaGenerator":
51
+ ) -> DeltaGenerator:
50
52
  """Display text in header formatting.
51
53
 
52
54
  Parameters
@@ -114,9 +116,9 @@ class HeadingMixin:
114
116
  body: SupportsStr,
115
117
  anchor: Anchor = None,
116
118
  *, # keyword-only arguments:
117
- help: Optional[str] = None,
119
+ help: str | None = None,
118
120
  divider: Divider = False,
119
- ) -> "DeltaGenerator":
121
+ ) -> DeltaGenerator:
120
122
  """Display text in subheader formatting.
121
123
 
122
124
  Parameters
@@ -184,8 +186,8 @@ class HeadingMixin:
184
186
  body: SupportsStr,
185
187
  anchor: Anchor = None,
186
188
  *, # keyword-only arguments:
187
- help: Optional[str] = None,
188
- ) -> "DeltaGenerator":
189
+ help: str | None = None,
190
+ ) -> DeltaGenerator:
189
191
  """Display text in title formatting.
190
192
 
191
193
  Each document should have a single `st.title()`, although this is not
@@ -239,12 +241,12 @@ class HeadingMixin:
239
241
  )
240
242
 
241
243
  @property
242
- def dg(self) -> "DeltaGenerator":
244
+ def dg(self) -> DeltaGenerator:
243
245
  """Get our DeltaGenerator."""
244
246
  return cast("DeltaGenerator", self)
245
247
 
246
248
  @staticmethod
247
- def _handle_divider_color(divider):
249
+ def _handle_divider_color(divider: Divider) -> str:
248
250
  if divider is True:
249
251
  return "auto"
250
252
  valid_colors = [
@@ -258,7 +260,7 @@ class HeadingMixin:
258
260
  "rainbow",
259
261
  ]
260
262
  if divider in valid_colors:
261
- return divider
263
+ return cast(str, divider)
262
264
  else:
263
265
  raise StreamlitAPIException(
264
266
  f"Divider parameter has invalid value: `{divider}`. Please choose from: {', '.join(valid_colors)}."
@@ -269,7 +271,7 @@ class HeadingMixin:
269
271
  tag: HeadingProtoTag,
270
272
  body: SupportsStr,
271
273
  anchor: Anchor = None,
272
- help: Optional[str] = None,
274
+ help: str | None = None,
273
275
  divider: Divider = False,
274
276
  ) -> HeadingProto:
275
277
  proto = HeadingProto()
@@ -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.IFrame_pb2 import IFrame as IFrameProto
18
20
  from streamlit.runtime.metrics_util import gather_metrics
@@ -26,10 +28,10 @@ class IframeMixin:
26
28
  def _iframe(
27
29
  self,
28
30
  src: str,
29
- width: Optional[int] = None,
30
- height: Optional[int] = None,
31
+ width: int | None = None,
32
+ height: int | None = None,
31
33
  scrolling: bool = False,
32
- ) -> "DeltaGenerator":
34
+ ) -> DeltaGenerator:
33
35
  """Load a remote URL in an iframe.
34
36
 
35
37
  Parameters
@@ -60,10 +62,10 @@ class IframeMixin:
60
62
  def _html(
61
63
  self,
62
64
  html: str,
63
- width: Optional[int] = None,
64
- height: Optional[int] = None,
65
+ width: int | None = None,
66
+ height: int | None = None,
65
67
  scrolling: bool = False,
66
- ) -> "DeltaGenerator":
68
+ ) -> DeltaGenerator:
67
69
  """Display an HTML string in an iframe.
68
70
 
69
71
  Parameters
@@ -91,17 +93,17 @@ class IframeMixin:
91
93
  return self.dg._enqueue("iframe", iframe_proto)
92
94
 
93
95
  @property
94
- def dg(self) -> "DeltaGenerator":
96
+ def dg(self) -> DeltaGenerator:
95
97
  """Get our DeltaGenerator."""
96
98
  return cast("DeltaGenerator", self)
97
99
 
98
100
 
99
101
  def marshall(
100
102
  proto: IFrameProto,
101
- src: Optional[str] = None,
102
- srcdoc: Optional[str] = None,
103
- width: Optional[int] = None,
104
- height: Optional[int] = None,
103
+ src: str | None = None,
104
+ srcdoc: str | None = None,
105
+ width: int | None = None,
106
+ height: int | None = None,
105
107
  scrolling: bool = False,
106
108
  ) -> None:
107
109
  """Marshalls data into an IFrame proto.
@@ -87,13 +87,13 @@ class ImageMixin:
87
87
  image: ImageOrImageList,
88
88
  # TODO: Narrow type of caption, dependent on type of image,
89
89
  # by way of overload
90
- caption: str | List[str] | None = None,
90
+ caption: str | list[str] | None = None,
91
91
  width: int | None = None,
92
92
  use_column_width: UseColumnWith = None,
93
93
  clamp: bool = False,
94
94
  channels: Channels = "RGB",
95
95
  output_format: ImageFormatOrAuto = "auto",
96
- ) -> "DeltaGenerator":
96
+ ) -> DeltaGenerator:
97
97
  """Display an image or list of images.
98
98
 
99
99
  Parameters
@@ -171,7 +171,7 @@ class ImageMixin:
171
171
  return self.dg._enqueue("imgs", image_list_proto)
172
172
 
173
173
  @property
174
- def dg(self) -> "DeltaGenerator":
174
+ def dg(self) -> DeltaGenerator:
175
175
  """Get our DeltaGenerator."""
176
176
  return cast("DeltaGenerator", self)
177
177
 
@@ -243,7 +243,7 @@ def _BytesIO_to_bytes(data: io.BytesIO) -> bytes:
243
243
  return data.getvalue()
244
244
 
245
245
 
246
- def _np_array_to_bytes(array: "npt.NDArray[Any]", output_format="JPEG") -> bytes:
246
+ def _np_array_to_bytes(array: npt.NDArray[Any], output_format: str = "JPEG") -> bytes:
247
247
  import numpy as np
248
248
  from PIL import Image
249
249
 
@@ -253,11 +253,11 @@ def _np_array_to_bytes(array: "npt.NDArray[Any]", output_format="JPEG") -> bytes
253
253
  return _PIL_to_bytes(img, format)
254
254
 
255
255
 
256
- def _4d_to_list_3d(array: "npt.NDArray[Any]") -> List["npt.NDArray[Any]"]:
256
+ def _4d_to_list_3d(array: npt.NDArray[Any]) -> list[npt.NDArray[Any]]:
257
257
  return [array[i, :, :, :] for i in range(0, array.shape[0])]
258
258
 
259
259
 
260
- def _verify_np_shape(array: "npt.NDArray[Any]") -> "npt.NDArray[Any]":
260
+ def _verify_np_shape(array: npt.NDArray[Any]) -> npt.NDArray[Any]:
261
261
  if len(array.shape) not in (2, 3):
262
262
  raise StreamlitAPIException("Numpy shape has to be of length 2 or 3.")
263
263
  if len(array.shape) == 3 and array.shape[-1] not in (1, 3, 4):
@@ -307,7 +307,7 @@ def _ensure_image_size_and_format(
307
307
  return image_data
308
308
 
309
309
 
310
- def _clip_image(image: "npt.NDArray[Any]", clamp: bool) -> "npt.NDArray[Any]":
310
+ def _clip_image(image: npt.NDArray[Any], clamp: bool) -> npt.NDArray[Any]:
311
311
  import numpy as np
312
312
 
313
313
  data = image
@@ -451,7 +451,7 @@ def image_to_url(
451
451
  def marshall_images(
452
452
  coordinates: str,
453
453
  image: ImageOrImageList,
454
- caption: str | "npt.NDArray[Any]" | List[str] | None,
454
+ caption: str | npt.NDArray[Any] | list[str] | None,
455
455
  width: int | WidthBehaviour,
456
456
  proto_imgs: ImageListProto,
457
457
  clamp: bool,
@@ -12,8 +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
  import json
16
- from typing import TYPE_CHECKING, Any, List, Union, cast
18
+ from typing import TYPE_CHECKING, Any, cast
17
19
 
18
20
  from streamlit.proto.Json_pb2 import Json as JsonProto
19
21
  from streamlit.runtime.metrics_util import gather_metrics
@@ -24,7 +26,7 @@ if TYPE_CHECKING:
24
26
  from streamlit.delta_generator import DeltaGenerator
25
27
 
26
28
 
27
- def _ensure_serialization(o: object) -> Union[str, List[Any]]:
29
+ def _ensure_serialization(o: object) -> str | list[Any]:
28
30
  """A repr function for json.dumps default arg, which tries to serialize sets as lists"""
29
31
  if isinstance(o, set):
30
32
  return list(o)
@@ -38,7 +40,7 @@ class JsonMixin:
38
40
  body: object,
39
41
  *, # keyword-only arguments:
40
42
  expanded: bool = True,
41
- ) -> "DeltaGenerator":
43
+ ) -> DeltaGenerator:
42
44
  """Display object or string as a pretty-printed JSON string.
43
45
 
44
46
  Parameters
@@ -94,6 +96,6 @@ class JsonMixin:
94
96
  return self.dg._enqueue("json", json_proto)
95
97
 
96
98
  @property
97
- def dg(self) -> "DeltaGenerator":
99
+ def dg(self) -> DeltaGenerator:
98
100
  """Get our DeltaGenerator."""
99
101
  return cast("DeltaGenerator", self)
@@ -14,7 +14,9 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import TYPE_CHECKING, List, Literal, Optional, Sequence, Union, cast
17
+ from typing import TYPE_CHECKING, Literal, Sequence, Union, cast
18
+
19
+ from typing_extensions import TypeAlias
18
20
 
19
21
  from streamlit.errors import StreamlitAPIException
20
22
  from streamlit.proto.Block_pb2 import Block as BlockProto
@@ -24,14 +26,14 @@ if TYPE_CHECKING:
24
26
  from streamlit.delta_generator import DeltaGenerator
25
27
  from streamlit.elements.lib.mutable_status_container import StatusContainer
26
28
 
27
- SpecType = Union[int, Sequence[Union[int, float]]]
29
+ SpecType: TypeAlias = Union[int, Sequence[Union[int, float]]]
28
30
 
29
31
 
30
32
  class LayoutsMixin:
31
33
  @gather_metrics("container")
32
34
  def container(
33
35
  self, *, height: int | None = None, border: bool | None = None
34
- ) -> "DeltaGenerator":
36
+ ) -> DeltaGenerator:
35
37
  """Insert a multi-element container.
36
38
 
37
39
  Inserts an invisible container into your app that can be used to hold
@@ -142,8 +144,8 @@ class LayoutsMixin:
142
144
  # TODO: Enforce that columns are not nested or in Sidebar
143
145
  @gather_metrics("columns")
144
146
  def columns(
145
- self, spec: SpecType, *, gap: Optional[str] = "small"
146
- ) -> List["DeltaGenerator"]:
147
+ self, spec: SpecType, *, gap: str | None = "small"
148
+ ) -> list[DeltaGenerator]:
147
149
  """Insert containers laid out as side-by-side columns.
148
150
 
149
151
  Inserts a number of multi-element containers laid out side-by-side and
@@ -268,7 +270,7 @@ class LayoutsMixin:
268
270
  return [row._block(column_proto(w / total_weight)) for w in weights]
269
271
 
270
272
  @gather_metrics("tabs")
271
- def tabs(self, tabs: Sequence[str]) -> Sequence["DeltaGenerator"]:
273
+ def tabs(self, tabs: Sequence[str]) -> Sequence[DeltaGenerator]:
272
274
  r"""Insert containers separated into tabs.
273
275
 
274
276
  Inserts a number of multi-element containers as tabs.
@@ -380,7 +382,7 @@ class LayoutsMixin:
380
382
  return tuple(tab_container._block(tab_proto(tab_label)) for tab_label in tabs)
381
383
 
382
384
  @gather_metrics("expander")
383
- def expander(self, label: str, expanded: bool = False) -> "DeltaGenerator":
385
+ def expander(self, label: str, expanded: bool = False) -> DeltaGenerator:
384
386
  r"""Insert a multi-element container that can be expanded/collapsed.
385
387
 
386
388
  Inserts a container into your app that can be used to hold multiple elements
@@ -481,8 +483,8 @@ class LayoutsMixin:
481
483
  *,
482
484
  expanded: bool = False,
483
485
  state: Literal["running", "complete", "error"] = "running",
484
- ) -> "StatusContainer":
485
- """Insert a status container to display output from long-running tasks.
486
+ ) -> StatusContainer:
487
+ r"""Insert a status container to display output from long-running tasks.
486
488
 
487
489
  Inserts a container into your app that is typically used to show the status and
488
490
  details of a process or task. The container can hold multiple elements and can
@@ -597,6 +599,6 @@ class LayoutsMixin:
597
599
  )
598
600
 
599
601
  @property
600
- def dg(self) -> "DeltaGenerator":
602
+ def dg(self) -> DeltaGenerator:
601
603
  """Get our DeltaGenerator."""
602
604
  return cast("DeltaGenerator", self)
@@ -16,7 +16,7 @@ from __future__ import annotations
16
16
 
17
17
  import json
18
18
  from enum import Enum
19
- from typing import TYPE_CHECKING, Dict, Final, List, Literal, Mapping, Union
19
+ from typing import TYPE_CHECKING, Dict, Final, Literal, Mapping, Union
20
20
 
21
21
  from typing_extensions import TypeAlias
22
22
 
@@ -69,7 +69,7 @@ DataframeSchema: TypeAlias = Dict[str, ColumnDataKind]
69
69
 
70
70
  # This mapping contains all editable column types mapped to the data kinds
71
71
  # that the column type is compatible for editing.
72
- _EDITING_COMPATIBILITY_MAPPING: Final[Dict[ColumnType, List[ColumnDataKind]]] = {
72
+ _EDITING_COMPATIBILITY_MAPPING: Final[dict[ColumnType, list[ColumnDataKind]]] = {
73
73
  "text": [ColumnDataKind.STRING, ColumnDataKind.EMPTY],
74
74
  "number": [
75
75
  ColumnDataKind.INTEGER,