streamlit-nightly 1.31.2.dev20240213__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 (153) 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 +8 -19
  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/storage/cache_storage_protocol.py +1 -2
  95. streamlit/runtime/caching/storage/local_disk_cache_storage.py +6 -5
  96. streamlit/runtime/connection_factory.py +8 -8
  97. streamlit/runtime/forward_msg_cache.py +20 -18
  98. streamlit/runtime/forward_msg_queue.py +8 -9
  99. streamlit/runtime/legacy_caching/caching.py +32 -42
  100. streamlit/runtime/media_file_manager.py +16 -14
  101. streamlit/runtime/media_file_storage.py +8 -8
  102. streamlit/runtime/memory_media_file_storage.py +12 -14
  103. streamlit/runtime/memory_session_storage.py +4 -3
  104. streamlit/runtime/memory_uploaded_file_manager.py +9 -10
  105. streamlit/runtime/metrics_util.py +20 -20
  106. streamlit/runtime/runtime.py +25 -27
  107. streamlit/runtime/runtime_util.py +5 -3
  108. streamlit/runtime/script_data.py +2 -0
  109. streamlit/runtime/scriptrunner/magic.py +17 -11
  110. streamlit/runtime/scriptrunner/magic_funcs.py +2 -0
  111. streamlit/runtime/scriptrunner/script_requests.py +6 -4
  112. streamlit/runtime/scriptrunner/script_run_context.py +17 -17
  113. streamlit/runtime/scriptrunner/script_runner.py +7 -5
  114. streamlit/runtime/secrets.py +4 -6
  115. streamlit/runtime/session_manager.py +14 -14
  116. streamlit/runtime/state/common.py +5 -4
  117. streamlit/runtime/state/query_params.py +8 -6
  118. streamlit/runtime/state/query_params_proxy.py +7 -5
  119. streamlit/runtime/state/safe_session_state.py +7 -5
  120. streamlit/runtime/state/session_state.py +3 -4
  121. streamlit/runtime/state/session_state_proxy.py +5 -5
  122. streamlit/runtime/state/widgets.py +20 -18
  123. streamlit/runtime/uploaded_file_manager.py +6 -5
  124. streamlit/runtime/websocket_session_manager.py +14 -14
  125. streamlit/source_util.py +13 -11
  126. streamlit/string_util.py +13 -9
  127. streamlit/temporary_directory.py +3 -1
  128. streamlit/testing/v1/element_tree.py +1 -2
  129. streamlit/type_util.py +21 -25
  130. streamlit/url_util.py +6 -4
  131. streamlit/user_info.py +8 -6
  132. streamlit/util.py +23 -37
  133. streamlit/watcher/event_based_path_watcher.py +10 -10
  134. streamlit/watcher/local_sources_watcher.py +15 -13
  135. streamlit/watcher/path_watcher.py +0 -3
  136. streamlit/watcher/polling_path_watcher.py +9 -8
  137. streamlit/watcher/util.py +3 -2
  138. streamlit/web/cache_storage_manager_config.py +2 -0
  139. streamlit/web/server/app_static_file_handler.py +6 -5
  140. streamlit/web/server/browser_websocket_handler.py +10 -8
  141. streamlit/web/server/component_request_handler.py +7 -4
  142. streamlit/web/server/media_file_handler.py +5 -4
  143. streamlit/web/server/routes.py +6 -3
  144. streamlit/web/server/server.py +31 -31
  145. streamlit/web/server/server_util.py +4 -2
  146. streamlit/web/server/upload_file_request_handler.py +7 -8
  147. streamlit/web/server/websocket_headers.py +2 -2
  148. {streamlit_nightly-1.31.2.dev20240213.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/METADATA +1 -1
  149. {streamlit_nightly-1.31.2.dev20240213.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/RECORD +153 -153
  150. {streamlit_nightly-1.31.2.dev20240213.data → streamlit_nightly-1.31.2.dev20240214.data}/scripts/streamlit.cmd +0 -0
  151. {streamlit_nightly-1.31.2.dev20240213.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/WHEEL +0 -0
  152. {streamlit_nightly-1.31.2.dev20240213.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/entry_points.txt +0 -0
  153. {streamlit_nightly-1.31.2.dev20240213.dist-info → streamlit_nightly-1.31.2.dev20240214.dist-info}/top_level.txt +0 -0
@@ -15,9 +15,9 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import datetime
18
- from typing import Iterable, List, Union
18
+ from typing import Iterable, Literal, TypedDict
19
19
 
20
- from typing_extensions import Literal, NotRequired, TypeAlias, TypedDict
20
+ from typing_extensions import NotRequired, TypeAlias
21
21
 
22
22
  from streamlit.runtime.metrics_util import gather_metrics
23
23
 
@@ -63,7 +63,7 @@ class CheckboxColumnConfig(TypedDict):
63
63
 
64
64
  class SelectboxColumnConfig(TypedDict):
65
65
  type: Literal["selectbox"]
66
- options: NotRequired[List[str | int | float] | None]
66
+ options: NotRequired[list[str | int | float] | None]
67
67
 
68
68
 
69
69
  class LinkColumnConfig(TypedDict):
@@ -167,22 +167,22 @@ class ColumnConfig(TypedDict, total=False):
167
167
  required: bool | None
168
168
  default: str | bool | int | float | None
169
169
  alignment: Literal["left", "center", "right"] | None
170
- type_config: Union[
171
- NumberColumnConfig,
172
- TextColumnConfig,
173
- CheckboxColumnConfig,
174
- SelectboxColumnConfig,
175
- LinkColumnConfig,
176
- ListColumnConfig,
177
- DatetimeColumnConfig,
178
- DateColumnConfig,
179
- TimeColumnConfig,
180
- ProgressColumnConfig,
181
- LineChartColumnConfig,
182
- BarChartColumnConfig,
183
- ImageColumnConfig,
184
- None,
185
- ]
170
+ type_config: (
171
+ NumberColumnConfig
172
+ | TextColumnConfig
173
+ | CheckboxColumnConfig
174
+ | SelectboxColumnConfig
175
+ | LinkColumnConfig
176
+ | ListColumnConfig
177
+ | DatetimeColumnConfig
178
+ | DateColumnConfig
179
+ | TimeColumnConfig
180
+ | ProgressColumnConfig
181
+ | LineChartColumnConfig
182
+ | BarChartColumnConfig
183
+ | ImageColumnConfig
184
+ | None
185
+ )
186
186
 
187
187
 
188
188
  @gather_metrics("column_config.Column")
@@ -382,7 +382,7 @@ def TextColumn(
382
382
  max_chars: int | None = None,
383
383
  validate: str | None = None,
384
384
  ) -> ColumnConfig:
385
- """Configure a text column in ``st.dataframe`` or ``st.data_editor``.
385
+ r"""Configure a text column in ``st.dataframe`` or ``st.data_editor``.
386
386
 
387
387
  This is the default column type for string values. This command needs to be used in the
388
388
  ``column_config`` parameter of ``st.dataframe`` or ``st.data_editor``. When used with
@@ -525,7 +525,7 @@ def LinkColumn(
525
525
 
526
526
  * A regular expression (JS flavor, detected by usage of parentheses)
527
527
  to extract a part of the URL via a capture group, e.g. ``"https://(.*?)\.streamlit\.app"``
528
- to extract the display text "foo" from the URL "\https://foo.streamlit.app".
528
+ to extract the display text "foo" from the URL "https://foo.streamlit.app".
529
529
 
530
530
  For more complex cases, you may use `Pandas Styler's format \
531
531
  <https://pandas.pydata.org/docs/reference/api/pandas.io.formats.style.Styler.format.html>`_
@@ -562,9 +562,9 @@ def LinkColumn(
562
562
  >>> "apps": st.column_config.LinkColumn(
563
563
  >>> "Trending apps",
564
564
  >>> help="The top trending Streamlit apps",
565
- >>> validate="^https://[a-z]+\.streamlit\.app$",
565
+ >>> validate="^https://[a-z]+\\.streamlit\\.app$",
566
566
  >>> max_chars=100,
567
- >>> display_text="https://(.*?)\.streamlit\.app"
567
+ >>> display_text="https://(.*?)\\.streamlit\\.app"
568
568
  >>> ),
569
569
  >>> "creator": st.column_config.LinkColumn(
570
570
  >>> "App Creator", display_text="Open profile"
@@ -14,10 +14,12 @@
14
14
 
15
15
  """Tools for working with dicts."""
16
16
 
17
- from typing import Any, Dict, Mapping, Optional
17
+ from __future__ import annotations
18
18
 
19
+ from typing import Any, Mapping
19
20
 
20
- def _unflatten_single_dict(flat_dict):
21
+
22
+ def _unflatten_single_dict(flat_dict: dict[Any, Any]) -> dict[Any, Any]:
21
23
  """Convert a flat dict of key-value pairs to dict tree.
22
24
 
23
25
  Example
@@ -54,11 +56,11 @@ def _unflatten_single_dict(flat_dict):
54
56
  A tree made of dicts inside of dicts.
55
57
 
56
58
  """
57
- out: Dict[str, Any] = dict()
59
+ out: dict[str, Any] = dict()
58
60
  for pathstr, v in flat_dict.items():
59
61
  path = pathstr.split("_")
60
62
 
61
- prev_dict: Optional[Dict[str, Any]] = None
63
+ prev_dict: dict[str, Any] | None = None
62
64
  curr_dict = out
63
65
 
64
66
  for k in path:
@@ -73,7 +75,9 @@ def _unflatten_single_dict(flat_dict):
73
75
  return out
74
76
 
75
77
 
76
- def unflatten(flat_dict, encodings=None):
78
+ def unflatten(
79
+ flat_dict: dict[Any, Any], encodings: set[str] | None = None
80
+ ) -> dict[Any, Any]:
77
81
  """Converts a flat dict of key-value pairs to a spec tree.
78
82
 
79
83
  Example
@@ -136,7 +140,7 @@ def unflatten(flat_dict, encodings=None):
136
140
  return out_dict
137
141
 
138
142
 
139
- def remove_none_values(input_dict: Mapping[Any, Any]) -> Dict[Any, Any]:
143
+ def remove_none_values(input_dict: Mapping[Any, Any]) -> dict[Any, Any]:
140
144
  """Remove all keys with None values from a dict."""
141
145
  new_dict = {}
142
146
  for key, val in input_dict.items():
@@ -16,9 +16,9 @@ from __future__ import annotations
16
16
 
17
17
  import time
18
18
  from types import TracebackType
19
- from typing import List, Optional, Type, cast
19
+ from typing import Literal, cast
20
20
 
21
- from typing_extensions import Literal, TypeAlias
21
+ from typing_extensions import TypeAlias
22
22
 
23
23
  from streamlit.cursor import Cursor
24
24
  from streamlit.delta_generator import DeltaGenerator, _enqueue_message
@@ -56,7 +56,7 @@ class StatusContainer(DeltaGenerator):
56
56
  block_proto.allow_empty = True
57
57
  block_proto.expandable.CopyFrom(expandable_proto)
58
58
 
59
- delta_path: List[int] = (
59
+ delta_path: list[int] = (
60
60
  parent._active_dg._cursor.delta_path if parent._active_dg._cursor else []
61
61
  )
62
62
 
@@ -90,7 +90,7 @@ class StatusContainer(DeltaGenerator):
90
90
  # Initialized in `_create()`:
91
91
  self._current_proto: BlockProto | None = None
92
92
  self._current_state: States | None = None
93
- self._delta_path: List[int] | None = None
93
+ self._delta_path: list[int] | None = None
94
94
 
95
95
  def update(
96
96
  self,
@@ -158,9 +158,9 @@ class StatusContainer(DeltaGenerator):
158
158
 
159
159
  def __exit__(
160
160
  self,
161
- exc_type: Optional[Type[BaseException]],
162
- exc_val: Optional[BaseException],
163
- exc_tb: Optional[TracebackType],
161
+ exc_type: type[BaseException] | None,
162
+ exc_val: BaseException | None,
163
+ exc_tb: TracebackType | None,
164
164
  ) -> Literal[False]:
165
165
  # Only update if the current state is running
166
166
  if self._current_state == "running":
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import TYPE_CHECKING, Any, List, Mapping, TypeVar
17
+ from typing import TYPE_CHECKING, Any, Mapping, TypeVar
18
18
 
19
19
  from streamlit import type_util
20
20
  from streamlit.errors import StreamlitAPIException
@@ -25,7 +25,7 @@ if TYPE_CHECKING:
25
25
  from pandas.io.formats.style import Styler
26
26
 
27
27
 
28
- def marshall_styler(proto: ArrowProto, styler: "Styler", default_uuid: str) -> None:
28
+ def marshall_styler(proto: ArrowProto, styler: Styler, default_uuid: str) -> None:
29
29
  """Marshall pandas.Styler into an Arrow proto.
30
30
 
31
31
  Parameters
@@ -66,7 +66,7 @@ def marshall_styler(proto: ArrowProto, styler: "Styler", default_uuid: str) -> N
66
66
  _marshall_display_values(proto, styler_data_df, pandas_styles)
67
67
 
68
68
 
69
- def _marshall_uuid(proto: ArrowProto, styler: "Styler", default_uuid: str) -> None:
69
+ def _marshall_uuid(proto: ArrowProto, styler: Styler, default_uuid: str) -> None:
70
70
  """Marshall pandas.Styler uuid into an Arrow proto.
71
71
 
72
72
  Parameters
@@ -87,7 +87,7 @@ def _marshall_uuid(proto: ArrowProto, styler: "Styler", default_uuid: str) -> No
87
87
  proto.styler.uuid = str(styler.uuid)
88
88
 
89
89
 
90
- def _marshall_caption(proto: ArrowProto, styler: "Styler") -> None:
90
+ def _marshall_caption(proto: ArrowProto, styler: Styler) -> None:
91
91
  """Marshall pandas.Styler caption into an Arrow proto.
92
92
 
93
93
  Parameters
@@ -104,7 +104,7 @@ def _marshall_caption(proto: ArrowProto, styler: "Styler") -> None:
104
104
 
105
105
 
106
106
  def _marshall_styles(
107
- proto: ArrowProto, styler: "Styler", styles: Mapping[str, Any]
107
+ proto: ArrowProto, styler: Styler, styles: Mapping[str, Any]
108
108
  ) -> None:
109
109
  """Marshall pandas.Styler styles into an Arrow proto.
110
110
 
@@ -147,7 +147,7 @@ def _marshall_styles(
147
147
  M = TypeVar("M", bound=Mapping[str, Any])
148
148
 
149
149
 
150
- def _trim_pandas_styles(styles: List[M]) -> List[M]:
150
+ def _trim_pandas_styles(styles: list[M]) -> list[M]:
151
151
  """Filter out empty styles.
152
152
 
153
153
  Every cell will have a class, but the list of props
@@ -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
 
17
19
 
streamlit/elements/map.py CHANGED
@@ -19,18 +19,7 @@ from __future__ import annotations
19
19
  import copy
20
20
  import hashlib
21
21
  import json
22
- from typing import (
23
- TYPE_CHECKING,
24
- Any,
25
- Collection,
26
- Dict,
27
- Final,
28
- Iterable,
29
- Set,
30
- Tuple,
31
- Union,
32
- cast,
33
- )
22
+ from typing import TYPE_CHECKING, Any, Collection, Dict, Final, Iterable, Union, cast
34
23
 
35
24
  from typing_extensions import TypeAlias
36
25
 
@@ -58,7 +47,7 @@ Data: TypeAlias = Union[
58
47
  ]
59
48
 
60
49
  # Map used as the basis for st.map.
61
- _DEFAULT_MAP: Final[Dict[str, Any]] = dict(deck_gl_json_chart.EMPTY_MAP)
50
+ _DEFAULT_MAP: Final[dict[str, Any]] = dict(deck_gl_json_chart.EMPTY_MAP)
62
51
 
63
52
  # Other default parameters for st.map.
64
53
  _DEFAULT_LAT_COL_NAMES: Final = {"lat", "latitude", "LAT", "LATITUDE"}
@@ -99,11 +88,11 @@ class MapMixin:
99
88
  *,
100
89
  latitude: str | None = None,
101
90
  longitude: str | None = None,
102
- color: Union[None, str, Color] = None,
103
- size: Union[None, str, float] = None,
91
+ color: None | str | Color = None,
92
+ size: None | str | float = None,
104
93
  zoom: int | None = None,
105
94
  use_container_width: bool = True,
106
- ) -> "DeltaGenerator":
95
+ ) -> DeltaGenerator:
107
96
  """Display a map with a scatterplot overlaid onto it.
108
97
 
109
98
  This is a wrapper around ``st.pydeck_chart`` to quickly create
@@ -247,7 +236,7 @@ class MapMixin:
247
236
  return self.dg._enqueue("deck_gl_json_chart", map_proto)
248
237
 
249
238
  @property
250
- def dg(self) -> "DeltaGenerator":
239
+ def dg(self) -> DeltaGenerator:
251
240
  """Get our DeltaGenerator."""
252
241
  return cast("DeltaGenerator", self)
253
242
 
@@ -327,7 +316,7 @@ def _get_lat_or_lon_col_name(
327
316
  data: DataFrame,
328
317
  human_readable_name: str,
329
318
  col_name_from_user: str | None,
330
- default_col_names: Set[str],
319
+ default_col_names: set[str],
331
320
  ) -> str:
332
321
  """Returns the column name to be used for latitude or longitude."""
333
322
 
@@ -373,7 +362,7 @@ def _get_value_and_col_name(
373
362
  data: DataFrame,
374
363
  value_or_name: Any,
375
364
  default_value: Any,
376
- ) -> Tuple[Any, str | None]:
365
+ ) -> tuple[Any, str | None]:
377
366
  """Take a value_or_name passed in by the Streamlit developer and return a PyDeck
378
367
  argument and column name for that property.
379
368
 
@@ -385,7 +374,7 @@ def _get_value_and_col_name(
385
374
  - If the user passes size="my_col_123", this returns "@@=my_col_123" and "my_col_123".
386
375
  """
387
376
 
388
- pydeck_arg: Union[str, float]
377
+ pydeck_arg: str | float
389
378
 
390
379
  if isinstance(value_or_name, str) and value_or_name in data.columns:
391
380
  col_name = value_or_name
@@ -416,7 +405,7 @@ def _convert_color_arg_or_column(
416
405
  NOTE: This function mutates the data argument.
417
406
  """
418
407
 
419
- color_arg_out: Union[None, str, IntColorTuple] = None
408
+ color_arg_out: None | str | IntColorTuple = None
420
409
 
421
410
  if color_col_name is not None:
422
411
  # Convert color column to the right format.
@@ -444,7 +433,7 @@ def _convert_color_arg_or_column(
444
433
 
445
434
  def _get_viewport_details(
446
435
  data: DataFrame, lat_col_name: str, lon_col_name: str, zoom: int | None
447
- ) -> Tuple[int, float, float]:
436
+ ) -> tuple[int, float, float]:
448
437
  """Auto-set viewport when not fully specified by user."""
449
438
  min_lat = data[lat_col_name].min()
450
439
  max_lat = data[lat_col_name].max()
@@ -12,20 +12,22 @@
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, Union, cast
15
+ from __future__ import annotations
16
+
17
+ from typing import TYPE_CHECKING, Final, cast
16
18
 
17
19
  from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto
18
20
  from streamlit.runtime.metrics_util import gather_metrics
19
21
  from streamlit.string_util import clean_text
20
22
  from streamlit.type_util import SupportsStr, is_sympy_expession
21
23
 
22
- MARKDOWN_HORIZONTAL_RULE_EXPRESSION = "---"
23
-
24
24
  if TYPE_CHECKING:
25
25
  import sympy
26
26
 
27
27
  from streamlit.delta_generator import DeltaGenerator
28
28
 
29
+ MARKDOWN_HORIZONTAL_RULE_EXPRESSION: Final = "---"
30
+
29
31
 
30
32
  class MarkdownMixin:
31
33
  @gather_metrics("markdown")
@@ -34,8 +36,8 @@ class MarkdownMixin:
34
36
  body: SupportsStr,
35
37
  unsafe_allow_html: bool = False,
36
38
  *, # keyword-only arguments:
37
- help: Optional[str] = None,
38
- ) -> "DeltaGenerator":
39
+ help: str | None = None,
40
+ ) -> DeltaGenerator:
39
41
  r"""Display string formatted as Markdown.
40
42
 
41
43
  Parameters
@@ -109,8 +111,8 @@ class MarkdownMixin:
109
111
  def code(
110
112
  self,
111
113
  body: SupportsStr,
112
- language: Optional[str] = "python",
113
- ) -> "DeltaGenerator":
114
+ language: str | None = "python",
115
+ ) -> DeltaGenerator:
114
116
  """Display a code block with optional syntax highlighting.
115
117
 
116
118
  (This is a convenience wrapper around `st.markdown()`)
@@ -149,8 +151,8 @@ class MarkdownMixin:
149
151
  body: SupportsStr,
150
152
  unsafe_allow_html: bool = False,
151
153
  *, # keyword-only arguments:
152
- help: Optional[str] = None,
153
- ) -> "DeltaGenerator":
154
+ help: str | None = None,
155
+ ) -> DeltaGenerator:
154
156
  """Display text in small font.
155
157
 
156
158
  This should be used for captions, asides, footnotes, sidenotes, and
@@ -210,10 +212,10 @@ class MarkdownMixin:
210
212
  @gather_metrics("latex")
211
213
  def latex(
212
214
  self,
213
- body: Union[SupportsStr, "sympy.Expr"],
215
+ body: SupportsStr | sympy.Expr,
214
216
  *, # keyword-only arguments:
215
- help: Optional[str] = None,
216
- ) -> "DeltaGenerator":
217
+ help: str | None = None,
218
+ ) -> DeltaGenerator:
217
219
  # This docstring needs to be "raw" because of the backslashes in the
218
220
  # example below.
219
221
  r"""Display mathematical expressions formatted as LaTeX.
@@ -256,7 +258,7 @@ class MarkdownMixin:
256
258
  return self.dg._enqueue("markdown", latex_proto)
257
259
 
258
260
  @gather_metrics("divider")
259
- def divider(self) -> "DeltaGenerator":
261
+ def divider(self) -> DeltaGenerator:
260
262
  """Display a horizontal rule.
261
263
 
262
264
  .. note::
@@ -276,6 +278,6 @@ class MarkdownMixin:
276
278
  return self.dg._enqueue("markdown", divider_proto)
277
279
 
278
280
  @property
279
- def dg(self) -> "DeltaGenerator":
281
+ def dg(self) -> DeltaGenerator:
280
282
  """Get our DeltaGenerator."""
281
283
  return cast("DeltaGenerator", self)
@@ -12,11 +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
  import io
16
18
  import re
17
- from typing import TYPE_CHECKING, Optional, Tuple, Union, cast
19
+ from typing import TYPE_CHECKING, Final, Union, cast
18
20
 
19
- from typing_extensions import Final, TypeAlias
21
+ from typing_extensions import TypeAlias
20
22
 
21
23
  import streamlit as st
22
24
  from streamlit import runtime, type_util, url_util
@@ -46,8 +48,8 @@ class MediaMixin:
46
48
  format: str = "audio/wav",
47
49
  start_time: int = 0,
48
50
  *,
49
- sample_rate: Optional[int] = None,
50
- ) -> "DeltaGenerator":
51
+ sample_rate: int | None = None,
52
+ ) -> DeltaGenerator:
51
53
  """Display an audio player.
52
54
 
53
55
  Parameters
@@ -118,7 +120,7 @@ class MediaMixin:
118
120
  data: MediaData,
119
121
  format: str = "video/mp4",
120
122
  start_time: int = 0,
121
- ) -> "DeltaGenerator":
123
+ ) -> DeltaGenerator:
122
124
  """Display a video player.
123
125
 
124
126
  Parameters
@@ -161,7 +163,7 @@ class MediaMixin:
161
163
  return self.dg._enqueue("video", video_proto)
162
164
 
163
165
  @property
164
- def dg(self) -> "DeltaGenerator":
166
+ def dg(self) -> DeltaGenerator:
165
167
  """Get our DeltaGenerator."""
166
168
  return cast("DeltaGenerator", self)
167
169
 
@@ -178,7 +180,7 @@ YOUTUBE_RE: Final = re.compile(
178
180
  )
179
181
 
180
182
 
181
- def _reshape_youtube_url(url: str) -> Optional[str]:
183
+ def _reshape_youtube_url(url: str) -> str | None:
182
184
  """Return whether URL is any kind of YouTube embed or watch link. If so,
183
185
  reshape URL into an embed link suitable for use in an iframe.
184
186
 
@@ -203,7 +205,7 @@ def _reshape_youtube_url(url: str) -> Optional[str]:
203
205
 
204
206
  def _marshall_av_media(
205
207
  coordinates: str,
206
- proto: Union[AudioProto, VideoProto],
208
+ proto: AudioProto | VideoProto,
207
209
  data: MediaData,
208
210
  mimetype: str,
209
211
  ) -> None:
@@ -224,7 +226,7 @@ def _marshall_av_media(
224
226
  # Allow empty values so media players can be shown without media.
225
227
  return
226
228
 
227
- data_or_filename: Union[bytes, str]
229
+ data_or_filename: bytes | str
228
230
  if isinstance(data, (str, bytes)):
229
231
  # Pass strings and bytes through unchanged
230
232
  data_or_filename = data
@@ -299,7 +301,7 @@ def marshall_video(
299
301
  _marshall_av_media(coordinates, proto, data, mimetype)
300
302
 
301
303
 
302
- def _validate_and_normalize(data: "npt.NDArray[Any]") -> Tuple[bytes, int]:
304
+ def _validate_and_normalize(data: npt.NDArray[Any]) -> tuple[bytes, int]:
303
305
  """Validates and normalizes numpy array data.
304
306
  We validate numpy array shape (should be 1d or 2d)
305
307
  We normalize input data to int16 [-32768, 32767] range.
@@ -321,7 +323,7 @@ def _validate_and_normalize(data: "npt.NDArray[Any]") -> Tuple[bytes, int]:
321
323
  # to st.audio data)
322
324
  import numpy as np
323
325
 
324
- data: "npt.NDArray[Any]" = np.array(data, dtype=float)
326
+ data: npt.NDArray[Any] = np.array(data, dtype=float)
325
327
 
326
328
  if len(data.shape) == 1:
327
329
  nchan = 1
@@ -348,7 +350,7 @@ def _validate_and_normalize(data: "npt.NDArray[Any]") -> Tuple[bytes, int]:
348
350
  return scaled_data.tobytes(), nchan
349
351
 
350
352
 
351
- def _make_wav(data: "npt.NDArray[Any]", sample_rate: int) -> bytes:
353
+ def _make_wav(data: npt.NDArray[Any], sample_rate: int) -> bytes:
352
354
  """
353
355
  Transform a numpy array to a PCM bytestring
354
356
  We use code from IPython display module to convert numpy array to wave bytes
@@ -369,9 +371,7 @@ def _make_wav(data: "npt.NDArray[Any]", sample_rate: int) -> bytes:
369
371
  return fp.getvalue()
370
372
 
371
373
 
372
- def _maybe_convert_to_wav_bytes(
373
- data: MediaData, sample_rate: Optional[int]
374
- ) -> MediaData:
374
+ def _maybe_convert_to_wav_bytes(data: MediaData, sample_rate: int | None) -> MediaData:
375
375
  """Convert data to wav bytes if the data type is numpy array."""
376
376
  if type_util.is_type(data, "numpy.ndarray") and sample_rate is not None:
377
377
  data = _make_wav(cast("npt.NDArray[Any]", data), sample_rate)
@@ -384,7 +384,7 @@ def marshall_audio(
384
384
  data: MediaData,
385
385
  mimetype: str = "audio/wav",
386
386
  start_time: int = 0,
387
- sample_rate: Optional[int] = None,
387
+ sample_rate: int | None = None,
388
388
  ) -> None:
389
389
  """Marshalls an audio proto, using data and url processors as needed.
390
390
 
@@ -12,11 +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, Literal, Union, cast
18
20
 
19
- from typing_extensions import Literal, TypeAlias
21
+ from typing_extensions import TypeAlias
20
22
 
21
23
  from streamlit.elements.utils import get_label_visibility_proto_value
22
24
  from streamlit.errors import StreamlitAPIException
@@ -38,8 +40,8 @@ DeltaColor: TypeAlias = Literal["normal", "inverse", "off"]
38
40
 
39
41
  @dataclass(frozen=True)
40
42
  class MetricColorAndDirection:
41
- color: "MetricProto.MetricColor.ValueType"
42
- direction: "MetricProto.MetricDirection.ValueType"
43
+ color: MetricProto.MetricColor.ValueType
44
+ direction: MetricProto.MetricDirection.ValueType
43
45
 
44
46
 
45
47
  class MetricMixin:
@@ -50,9 +52,9 @@ class MetricMixin:
50
52
  value: Value,
51
53
  delta: Delta = None,
52
54
  delta_color: DeltaColor = "normal",
53
- help: Optional[str] = None,
55
+ help: str | None = None,
54
56
  label_visibility: LabelVisibility = "visible",
55
- ) -> "DeltaGenerator":
57
+ ) -> DeltaGenerator:
56
58
  r"""Display a metric in big bold font, with an optional indicator of how the metric changed.
57
59
 
58
60
  Tip: If you want to display a large number, it may be a good idea to
@@ -165,7 +167,7 @@ class MetricMixin:
165
167
  return self.dg._enqueue("metric", metric_proto)
166
168
 
167
169
  @property
168
- def dg(self) -> "DeltaGenerator":
170
+ def dg(self) -> DeltaGenerator:
169
171
  return cast("DeltaGenerator", self)
170
172
 
171
173
 
@@ -18,7 +18,7 @@ from __future__ import annotations
18
18
 
19
19
  import json
20
20
  import urllib.parse
21
- from typing import TYPE_CHECKING, Any, Dict, List, Literal, Set, Union, cast
21
+ from typing import TYPE_CHECKING, Any, Dict, List, Literal, Union, cast
22
22
 
23
23
  from typing_extensions import TypeAlias
24
24
 
@@ -43,7 +43,7 @@ configure_streamlit_plotly_theme()
43
43
 
44
44
  SharingMode: TypeAlias = Literal["streamlit", "private", "public", "secret"]
45
45
 
46
- SHARING_MODES: Set[SharingMode] = {
46
+ SHARING_MODES: set[SharingMode] = {
47
47
  # This means the plot will be sent to the Streamlit app rather than to
48
48
  # Plotly.
49
49
  "streamlit",
@@ -79,7 +79,7 @@ class PlotlyMixin:
79
79
  sharing: SharingMode = "streamlit",
80
80
  theme: Literal["streamlit"] | None = "streamlit",
81
81
  **kwargs: Any,
82
- ) -> "DeltaGenerator":
82
+ ) -> DeltaGenerator:
83
83
  """Display an interactive Plotly chart.
84
84
 
85
85
  Plotly is a charting library for Python. The arguments to this function
@@ -164,7 +164,7 @@ class PlotlyMixin:
164
164
  return self.dg._enqueue("plotly_chart", plotly_chart_proto)
165
165
 
166
166
  @property
167
- def dg(self) -> "DeltaGenerator":
167
+ def dg(self) -> DeltaGenerator:
168
168
  """Get our DeltaGenerator."""
169
169
  return cast("DeltaGenerator", self)
170
170
 
@@ -220,7 +220,7 @@ def marshall(
220
220
 
221
221
 
222
222
  @caching.cache
223
- def _plot_to_url_or_load_cached_url(*args: Any, **kwargs: Any) -> "go.Figure":
223
+ def _plot_to_url_or_load_cached_url(*args: Any, **kwargs: Any) -> go.Figure:
224
224
  """Call plotly.plot wrapped in st.cache.
225
225
 
226
226
  This is so we don't unnecessarily upload data to Plotly's SASS if nothing
@@ -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 math
16
- from typing import TYPE_CHECKING, Optional, Union, cast
18
+ from typing import TYPE_CHECKING, Union, cast
17
19
 
18
20
  from typing_extensions import TypeAlias
19
21
 
@@ -78,7 +80,7 @@ def _get_value(value):
78
80
  )
79
81
 
80
82
 
81
- def _get_text(text: Optional[str]) -> Optional[str]:
83
+ def _get_text(text: str | None) -> str | None:
82
84
  if text is None:
83
85
  return None
84
86
  if isinstance(text, str):
@@ -90,9 +92,7 @@ def _get_text(text: Optional[str]) -> Optional[str]:
90
92
 
91
93
 
92
94
  class ProgressMixin:
93
- def progress(
94
- self, value: FloatOrInt, text: Optional[str] = None
95
- ) -> "DeltaGenerator":
95
+ def progress(self, value: FloatOrInt, text: str | None = None) -> DeltaGenerator:
96
96
  r"""Display a progress bar.
97
97
 
98
98
  Parameters
@@ -157,6 +157,6 @@ class ProgressMixin:
157
157
  return self.dg._enqueue("progress", progress_proto)
158
158
 
159
159
  @property
160
- def dg(self) -> "DeltaGenerator":
160
+ def dg(self) -> DeltaGenerator:
161
161
  """Get our DeltaGenerator."""
162
162
  return cast("DeltaGenerator", self)