streamlit-nightly 1.35.1.dev20240610__py2.py3-none-any.whl → 1.35.1.dev20240612__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 (121) hide show
  1. streamlit/__init__.py +5 -1
  2. streamlit/case_converters.py +2 -2
  3. streamlit/cli_util.py +2 -2
  4. streamlit/color_util.py +2 -2
  5. streamlit/commands/experimental_query_params.py +6 -8
  6. streamlit/commands/logo.py +4 -9
  7. streamlit/commands/navigation.py +6 -4
  8. streamlit/components/lib/local_component_registry.py +4 -2
  9. streamlit/components/types/base_component_registry.py +3 -2
  10. streamlit/components/v1/component_arrow.py +2 -1
  11. streamlit/components/v1/component_registry.py +6 -2
  12. streamlit/components/v1/components.py +4 -2
  13. streamlit/components/v1/custom_component.py +6 -6
  14. streamlit/config.py +15 -12
  15. streamlit/connections/snowflake_connection.py +2 -1
  16. streamlit/connections/snowpark_connection.py +2 -4
  17. streamlit/connections/sql_connection.py +2 -1
  18. streamlit/delta_generator.py +3 -4
  19. streamlit/elements/arrow.py +3 -6
  20. streamlit/elements/code.py +1 -1
  21. streamlit/elements/dialog_decorator.py +10 -8
  22. streamlit/elements/doc_string.py +1 -1
  23. streamlit/elements/exception.py +1 -1
  24. streamlit/elements/form.py +1 -1
  25. streamlit/elements/heading.py +1 -1
  26. streamlit/elements/html.py +1 -1
  27. streamlit/elements/image.py +5 -3
  28. streamlit/elements/layouts.py +36 -13
  29. streamlit/elements/lib/built_in_chart_utils.py +24 -12
  30. streamlit/elements/lib/column_config_utils.py +2 -1
  31. streamlit/elements/lib/dialog.py +8 -5
  32. streamlit/elements/lib/dicttools.py +3 -3
  33. streamlit/elements/lib/mutable_status_container.py +8 -5
  34. streamlit/elements/lib/pandas_styler_utils.py +2 -1
  35. streamlit/elements/lib/subtitle_utils.py +0 -1
  36. streamlit/elements/lib/utils.py +8 -10
  37. streamlit/elements/plotly_chart.py +5 -10
  38. streamlit/elements/pyplot.py +0 -1
  39. streamlit/elements/toast.py +2 -2
  40. streamlit/elements/vega_charts.py +46 -10
  41. streamlit/elements/widgets/color_picker.py +6 -4
  42. streamlit/elements/widgets/file_uploader.py +4 -8
  43. streamlit/elements/widgets/multiselect.py +2 -4
  44. streamlit/elements/widgets/number_input.py +4 -8
  45. streamlit/elements/widgets/select_slider.py +1 -1
  46. streamlit/elements/widgets/slider.py +2 -5
  47. streamlit/elements/widgets/time_widgets.py +5 -5
  48. streamlit/errors.py +1 -6
  49. streamlit/git_util.py +2 -2
  50. streamlit/hello/Animation_Demo.py +0 -1
  51. streamlit/logger.py +1 -1
  52. streamlit/navigation/page.py +6 -1
  53. streamlit/net_util.py +2 -5
  54. streamlit/proto/AutoRerun_pb2.py +3 -2
  55. streamlit/proto/Block_pb2.py +24 -22
  56. streamlit/proto/Block_pb2.pyi +19 -1
  57. streamlit/runtime/app_session.py +7 -7
  58. streamlit/runtime/caching/__init__.py +9 -13
  59. streamlit/runtime/caching/cache_data_api.py +18 -7
  60. streamlit/runtime/caching/cache_errors.py +8 -6
  61. streamlit/runtime/caching/cache_resource_api.py +10 -9
  62. streamlit/runtime/caching/cache_utils.py +10 -7
  63. streamlit/runtime/caching/cached_message_replay.py +10 -9
  64. streamlit/runtime/caching/hashing.py +3 -3
  65. streamlit/runtime/caching/storage/cache_storage_protocol.py +1 -1
  66. streamlit/runtime/connection_factory.py +4 -2
  67. streamlit/runtime/credentials.py +11 -20
  68. streamlit/runtime/forward_msg_cache.py +10 -11
  69. streamlit/runtime/forward_msg_queue.py +6 -4
  70. streamlit/runtime/fragment.py +7 -9
  71. streamlit/runtime/media_file_manager.py +4 -4
  72. streamlit/runtime/memory_media_file_storage.py +7 -8
  73. streamlit/runtime/metrics_util.py +2 -4
  74. streamlit/runtime/pages_manager.py +41 -41
  75. streamlit/runtime/runtime.py +4 -4
  76. streamlit/runtime/runtime_util.py +7 -12
  77. streamlit/runtime/scriptrunner/magic.py +1 -1
  78. streamlit/runtime/scriptrunner/script_requests.py +4 -2
  79. streamlit/runtime/scriptrunner/script_run_context.py +15 -15
  80. streamlit/runtime/scriptrunner/script_runner.py +8 -8
  81. streamlit/runtime/secrets.py +3 -5
  82. streamlit/runtime/session_manager.py +8 -7
  83. streamlit/runtime/state/common.py +1 -1
  84. streamlit/runtime/state/query_params_proxy.py +5 -10
  85. streamlit/runtime/state/safe_session_state.py +8 -7
  86. streamlit/runtime/state/widgets.py +27 -27
  87. streamlit/runtime/stats.py +1 -1
  88. streamlit/runtime/uploaded_file_manager.py +4 -2
  89. streamlit/runtime/websocket_session_manager.py +6 -4
  90. streamlit/static/asset-manifest.json +3 -3
  91. streamlit/static/index.html +1 -1
  92. streamlit/static/static/js/{8492.8ad745d1.chunk.js → 4335.b492cdb7.chunk.js} +1 -1
  93. streamlit/static/static/js/main.0ebf040e.js +2 -0
  94. streamlit/string_util.py +1 -1
  95. streamlit/testing/v1/app_test.py +4 -2
  96. streamlit/testing/v1/element_tree.py +33 -37
  97. streamlit/testing/v1/local_script_runner.py +7 -7
  98. streamlit/time_util.py +2 -4
  99. streamlit/type_util.py +16 -29
  100. streamlit/user_info.py +4 -2
  101. streamlit/util.py +1 -1
  102. streamlit/watcher/event_based_path_watcher.py +6 -3
  103. streamlit/watcher/local_sources_watcher.py +11 -7
  104. streamlit/web/bootstrap.py +1 -1
  105. streamlit/web/cache_storage_manager_config.py +5 -1
  106. streamlit/web/cli.py +9 -4
  107. streamlit/web/server/browser_websocket_handler.py +7 -8
  108. streamlit/web/server/component_request_handler.py +4 -2
  109. streamlit/web/server/routes.py +3 -3
  110. streamlit/web/server/server.py +12 -12
  111. streamlit/web/server/server_util.py +5 -6
  112. streamlit/web/server/stats_request_handler.py +1 -1
  113. streamlit/web/server/upload_file_request_handler.py +5 -3
  114. {streamlit_nightly-1.35.1.dev20240610.dist-info → streamlit_nightly-1.35.1.dev20240612.dist-info}/METADATA +1 -1
  115. {streamlit_nightly-1.35.1.dev20240610.dist-info → streamlit_nightly-1.35.1.dev20240612.dist-info}/RECORD +120 -120
  116. streamlit/static/static/js/main.dc75074b.js +0 -2
  117. /streamlit/static/static/js/{main.dc75074b.js.LICENSE.txt → main.0ebf040e.js.LICENSE.txt} +0 -0
  118. {streamlit_nightly-1.35.1.dev20240610.data → streamlit_nightly-1.35.1.dev20240612.data}/scripts/streamlit.cmd +0 -0
  119. {streamlit_nightly-1.35.1.dev20240610.dist-info → streamlit_nightly-1.35.1.dev20240612.dist-info}/WHEEL +0 -0
  120. {streamlit_nightly-1.35.1.dev20240610.dist-info → streamlit_nightly-1.35.1.dev20240612.dist-info}/entry_points.txt +0 -0
  121. {streamlit_nightly-1.35.1.dev20240610.dist-info → streamlit_nightly-1.35.1.dev20240612.dist-info}/top_level.txt +0 -0
@@ -150,7 +150,7 @@ class ImageMixin:
150
150
 
151
151
  if use_column_width == "auto" or (use_column_width is None and width is None):
152
152
  width = WidthBehaviour.AUTO
153
- elif use_column_width == "always" or use_column_width == True:
153
+ elif use_column_width == "always" or use_column_width is True:
154
154
  width = WidthBehaviour.COLUMN
155
155
  elif width is None:
156
156
  width = WidthBehaviour.ORIGINAL
@@ -513,7 +513,7 @@ def marshall_images(
513
513
  else:
514
514
  images = [image]
515
515
 
516
- if type(caption) is list:
516
+ if isinstance(caption, list):
517
517
  captions: Sequence[str | None] = caption
518
518
  else:
519
519
  if isinstance(caption, str):
@@ -528,7 +528,9 @@ def marshall_images(
528
528
  else:
529
529
  captions = [str(caption)]
530
530
 
531
- assert type(captions) == list, "If image is a list then caption should be as well"
531
+ assert isinstance(
532
+ captions, list
533
+ ), "If image is a list then caption should be as well"
532
534
  assert len(captions) == len(images), "Cannot pair %d captions with %d images." % (
533
535
  len(captions),
534
536
  len(images),
@@ -130,6 +130,7 @@ class LayoutsMixin:
130
130
  block_proto = BlockProto()
131
131
  block_proto.allow_empty = False
132
132
  block_proto.vertical.border = border or False
133
+
133
134
  if height:
134
135
  # Activate scrolling container behavior:
135
136
  block_proto.allow_empty = True
@@ -144,7 +145,11 @@ class LayoutsMixin:
144
145
 
145
146
  @gather_metrics("columns")
146
147
  def columns(
147
- self, spec: SpecType, *, gap: str | None = "small"
148
+ self,
149
+ spec: SpecType,
150
+ *,
151
+ gap: Literal["small", "medium", "large"] = "small",
152
+ vertical_alignment: Literal["top", "center", "bottom"] = "top",
148
153
  ) -> list[DeltaGenerator]:
149
154
  """Insert containers laid out as side-by-side columns.
150
155
 
@@ -176,6 +181,9 @@ class LayoutsMixin:
176
181
  gap : "small", "medium", or "large"
177
182
  The size of the gap between the columns. Defaults to "small".
178
183
 
184
+ vertical_alignment : "top", "center", or "bottom"
185
+ The vertical alignment of the content inside the columns. Defaults to "top".
186
+
179
187
  Returns
180
188
  -------
181
189
  list of containers
@@ -225,13 +233,6 @@ class LayoutsMixin:
225
233
 
226
234
  """
227
235
  weights = spec
228
- weights_exception = StreamlitAPIException(
229
- "The input argument to st.columns must be either a "
230
- + "positive integer or a list of positive numeric weights. "
231
- + "See [documentation](https://docs.streamlit.io/library/api-reference/layout/st.columns) "
232
- + "for more information."
233
- )
234
-
235
236
  if isinstance(weights, int):
236
237
  # If the user provided a single number, expand into equal weights.
237
238
  # E.g. (1,) * 3 => (1, 1, 1)
@@ -239,10 +240,29 @@ class LayoutsMixin:
239
240
  weights = (1,) * weights
240
241
 
241
242
  if len(weights) == 0 or any(weight <= 0 for weight in weights):
242
- raise weights_exception
243
+ raise StreamlitAPIException(
244
+ "The input argument to st.columns must be either a "
245
+ "positive integer or a list of positive numeric weights. "
246
+ "See [documentation](https://docs.streamlit.io/library/api-reference/layout/st.columns) "
247
+ "for more information."
248
+ )
249
+
250
+ vertical_alignment_mapping: dict[
251
+ str, BlockProto.Column.VerticalAlignment.ValueType
252
+ ] = {
253
+ "top": BlockProto.Column.VerticalAlignment.TOP,
254
+ "center": BlockProto.Column.VerticalAlignment.CENTER,
255
+ "bottom": BlockProto.Column.VerticalAlignment.BOTTOM,
256
+ }
257
+
258
+ if vertical_alignment not in vertical_alignment_mapping:
259
+ raise StreamlitAPIException(
260
+ 'The `vertical_alignment` argument to st.columns must be "top", "center", or "bottom". \n'
261
+ f"The argument passed was {vertical_alignment}."
262
+ )
243
263
 
244
264
  def column_gap(gap):
245
- if type(gap) == str:
265
+ if isinstance(gap, str):
246
266
  gap_size = gap.lower()
247
267
  valid_sizes = ["small", "medium", "large"]
248
268
 
@@ -260,6 +280,9 @@ class LayoutsMixin:
260
280
  col_proto = BlockProto()
261
281
  col_proto.column.weight = normalized_weight
262
282
  col_proto.column.gap = gap_size
283
+ col_proto.column.vertical_alignment = vertical_alignment_mapping[
284
+ vertical_alignment
285
+ ]
263
286
  col_proto.allow_empty = True
264
287
  return col_proto
265
288
 
@@ -368,7 +391,7 @@ class LayoutsMixin:
368
391
  "The input argument to st.tabs must contain at least one tab label."
369
392
  )
370
393
 
371
- if any(isinstance(tab, str) == False for tab in tabs):
394
+ if any(not isinstance(tab, str) for tab in tabs):
372
395
  raise StreamlitAPIException(
373
396
  "The tabs input list to st.tabs is only allowed to contain strings."
374
397
  )
@@ -490,7 +513,7 @@ class LayoutsMixin:
490
513
  help: str | None = None,
491
514
  disabled: bool = False,
492
515
  use_container_width: bool = False,
493
- ) -> "DeltaGenerator":
516
+ ) -> DeltaGenerator:
494
517
  r"""Insert a popover container.
495
518
 
496
519
  Inserts a multi-element container as a popover. It consists of a button-like
@@ -737,7 +760,7 @@ class LayoutsMixin:
737
760
  *,
738
761
  dismissible: bool = True,
739
762
  width: Literal["small", "large"] = "small",
740
- ) -> "Dialog":
763
+ ) -> Dialog:
741
764
  """Inserts the dialog container.
742
765
 
743
766
  Marked as internal because it is used by the dialog_decorator and is not supposed to be used directly.
@@ -88,8 +88,8 @@ class ChartType(Enum):
88
88
  # NOTE #2: In theory, we could move COLOR_LEGEND_SETTINGS into
89
89
  # ArrowVegaLiteChart/CustomTheme.tsx, but this would impact existing behavior.
90
90
  # (See https://github.com/streamlit/streamlit/pull/7164#discussion_r1307707345)
91
- _COLOR_LEGEND_SETTINGS: Final = dict(titlePadding=5, offset=5, orient="bottom")
92
- _SIZE_LEGEND_SETTINGS: Final = dict(titlePadding=0.5, offset=5, orient="bottom")
91
+ _COLOR_LEGEND_SETTINGS: Final = {"titlePadding": 5, "offset": 5, "orient": "bottom"}
92
+ _SIZE_LEGEND_SETTINGS: Final = {"titlePadding": 0.5, "offset": 5, "orient": "bottom"}
93
93
 
94
94
  # User-readable names to give the index and melted columns.
95
95
  _SEPARATED_INDEX_COLUMN_TITLE: Final = "index"
@@ -116,6 +116,8 @@ def generate_chart(
116
116
  data: Data | None,
117
117
  x_from_user: str | None = None,
118
118
  y_from_user: str | Sequence[str] | None = None,
119
+ x_axis_label: str | None = None,
120
+ y_axis_label: str | None = None,
119
121
  color_from_user: str | Color | list[Color] | None = None,
120
122
  size_from_user: str | float | None = None,
121
123
  width: int | None = None,
@@ -146,12 +148,12 @@ def generate_chart(
146
148
  # The last index of df so we can adjust the input df in add_rows:
147
149
  last_index=_last_index_for_melted_dataframes(df),
148
150
  # This is the input to prep_data (except for the df):
149
- columns=dict(
150
- x_column=x_column,
151
- y_column_list=y_column_list,
152
- color_column=color_column,
153
- size_column=size_column,
154
- ),
151
+ columns={
152
+ "x_column": x_column,
153
+ "y_column_list": y_column_list,
154
+ "color_column": color_column,
155
+ "size_column": size_column,
156
+ },
155
157
  )
156
158
 
157
159
  # At this point, all foo_column variables are either None/empty or contain actual
@@ -170,8 +172,8 @@ def generate_chart(
170
172
  width=width or 0,
171
173
  height=height or 0,
172
174
  ).encode(
173
- x=_get_x_encoding(df, x_column, x_from_user, chart_type),
174
- y=_get_y_encoding(df, y_column, y_from_user),
175
+ x=_get_x_encoding(df, x_column, x_from_user, x_axis_label, chart_type),
176
+ y=_get_y_encoding(df, y_column, y_from_user, y_axis_label),
175
177
  )
176
178
 
177
179
  # Set up opacity encoding.
@@ -539,7 +541,7 @@ def _parse_y_columns(
539
541
  y_column_list = [y_from_user]
540
542
 
541
543
  elif type_util.is_sequence(y_from_user):
542
- y_column_list = list(str(col) for col in y_from_user)
544
+ y_column_list = [str(col) for col in y_from_user]
543
545
 
544
546
  else:
545
547
  raise StreamlitAPIException(
@@ -619,6 +621,7 @@ def _get_x_encoding(
619
621
  df: pd.DataFrame,
620
622
  x_column: str | None,
621
623
  x_from_user: str | None,
624
+ x_axis_label: str | None,
622
625
  chart_type: ChartType,
623
626
  ) -> alt.X:
624
627
  import altair as alt
@@ -646,6 +649,10 @@ def _get_x_encoding(
646
649
  else:
647
650
  x_title = x_column
648
651
 
652
+ # User specified x-axis label takes precedence
653
+ if x_axis_label is not None:
654
+ x_title = x_axis_label
655
+
649
656
  return alt.X(
650
657
  x_field,
651
658
  title=x_title,
@@ -659,6 +666,7 @@ def _get_y_encoding(
659
666
  df: pd.DataFrame,
660
667
  y_column: str | None,
661
668
  y_from_user: str | Sequence[str] | None,
669
+ y_axis_label: str | None,
662
670
  ) -> alt.Y:
663
671
  import altair as alt
664
672
 
@@ -685,6 +693,10 @@ def _get_y_encoding(
685
693
  else:
686
694
  y_title = y_column
687
695
 
696
+ # User specified y-axis label takes precedence
697
+ if y_axis_label is not None:
698
+ y_title = y_axis_label
699
+
688
700
  return alt.Y(
689
701
  field=y_field,
690
702
  title=y_title,
@@ -703,7 +715,7 @@ def _get_color_encoding(
703
715
  ) -> alt.Color | alt.ColorValue | None:
704
716
  import altair as alt
705
717
 
706
- has_color_value = color_value not in [None, [], tuple()]
718
+ has_color_value = color_value not in [None, [], ()] # type: ignore[comparison-overlap]
707
719
 
708
720
  # If user passed a color value, that should win over colors coming from the
709
721
  # color column (be they manual or auto-assigned due to melting)
@@ -24,13 +24,14 @@ from typing_extensions import TypeAlias
24
24
  from streamlit.elements.lib.column_types import ColumnConfig, ColumnType
25
25
  from streamlit.elements.lib.dicttools import remove_none_values
26
26
  from streamlit.errors import StreamlitAPIException
27
- from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
28
27
  from streamlit.type_util import DataFormat, is_colum_type_arrow_incompatible
29
28
 
30
29
  if TYPE_CHECKING:
31
30
  import pyarrow as pa
32
31
  from pandas import DataFrame, Index, Series
33
32
 
33
+ from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
34
+
34
35
 
35
36
  # The index identifier can be used to apply configuration options
36
37
  IndexIdentifierType = Literal["_index"]
@@ -15,18 +15,21 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import time
18
- from types import TracebackType
19
- from typing import Literal, cast
18
+ from typing import TYPE_CHECKING, Literal, cast
20
19
 
21
- from typing_extensions import TypeAlias
20
+ from typing_extensions import Self, TypeAlias
22
21
 
23
- from streamlit.cursor import Cursor
24
22
  from streamlit.delta_generator import DeltaGenerator, _enqueue_message
25
23
  from streamlit.errors import StreamlitAPIException
26
24
  from streamlit.proto.Block_pb2 import Block as BlockProto
27
25
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
28
26
  from streamlit.runtime.scriptrunner import get_script_run_ctx
29
27
 
28
+ if TYPE_CHECKING:
29
+ from types import TracebackType
30
+
31
+ from streamlit.cursor import Cursor
32
+
30
33
  DialogWidth: TypeAlias = Literal["small", "large"]
31
34
 
32
35
 
@@ -132,7 +135,7 @@ class Dialog(DeltaGenerator):
132
135
  def close(self) -> None:
133
136
  self._update(False)
134
137
 
135
- def __enter__(self) -> Dialog: # type: ignore[override]
138
+ def __enter__(self) -> Self: # type: ignore[override]
136
139
  # This is a little dubious: we're returning a different type than
137
140
  # our superclass' `__enter__` function. Maybe DeltaGenerator.__enter__
138
141
  # should always return `self`?
@@ -56,7 +56,7 @@ def _unflatten_single_dict(flat_dict: dict[Any, Any]) -> dict[Any, Any]:
56
56
  A tree made of dicts inside of dicts.
57
57
 
58
58
  """
59
- out: dict[str, Any] = dict()
59
+ out: dict[str, Any] = {}
60
60
  for pathstr, v in flat_dict.items():
61
61
  path = pathstr.split("_")
62
62
 
@@ -65,7 +65,7 @@ def _unflatten_single_dict(flat_dict: dict[Any, Any]) -> dict[Any, Any]:
65
65
 
66
66
  for k in path:
67
67
  if k not in curr_dict:
68
- curr_dict[k] = dict()
68
+ curr_dict[k] = {}
69
69
  prev_dict = curr_dict
70
70
  curr_dict = curr_dict[k]
71
71
 
@@ -133,7 +133,7 @@ def unflatten(
133
133
  # Move items into 'encoding' if needed:
134
134
  if k in encodings:
135
135
  if "encoding" not in out_dict:
136
- out_dict["encoding"] = dict()
136
+ out_dict["encoding"] = {}
137
137
  out_dict["encoding"][k] = v
138
138
  out_dict.pop(k)
139
139
 
@@ -15,17 +15,20 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import time
18
- from types import TracebackType
19
- from typing import Literal, cast
18
+ from typing import TYPE_CHECKING, Literal, cast
20
19
 
21
- from typing_extensions import TypeAlias
20
+ from typing_extensions import Self, TypeAlias
22
21
 
23
- from streamlit.cursor import Cursor
24
22
  from streamlit.delta_generator import DeltaGenerator, _enqueue_message
25
23
  from streamlit.errors import StreamlitAPIException
26
24
  from streamlit.proto.Block_pb2 import Block as BlockProto
27
25
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
28
26
 
27
+ if TYPE_CHECKING:
28
+ from types import TracebackType
29
+
30
+ from streamlit.cursor import Cursor
31
+
29
32
  States: TypeAlias = Literal["running", "complete", "error"]
30
33
 
31
34
 
@@ -149,7 +152,7 @@ class StatusContainer(DeltaGenerator):
149
152
  self._current_proto = msg.delta.add_block
150
153
  _enqueue_message(msg)
151
154
 
152
- def __enter__(self) -> StatusContainer: # type: ignore[override]
155
+ def __enter__(self) -> Self: # type: ignore[override]
153
156
  # This is a little dubious: we're returning a different type than
154
157
  # our superclass' `__enter__` function. Maybe DeltaGenerator.__enter__
155
158
  # should always return `self`?
@@ -18,12 +18,13 @@ from typing import TYPE_CHECKING, Any, Mapping, TypeVar
18
18
 
19
19
  from streamlit import type_util
20
20
  from streamlit.errors import StreamlitAPIException
21
- from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
22
21
 
23
22
  if TYPE_CHECKING:
24
23
  from pandas import DataFrame
25
24
  from pandas.io.formats.style import Styler
26
25
 
26
+ from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
27
+
27
28
 
28
29
  def marshall_styler(proto: ArrowProto, styler: Styler, default_uuid: str) -> None:
29
30
  """Marshall pandas.Styler into an Arrow proto.
@@ -150,7 +150,6 @@ def process_subtitle_data(
150
150
  data: str | bytes | Path | io.BytesIO,
151
151
  label: str,
152
152
  ) -> str:
153
-
154
153
  # Determine the type of data and process accordingly
155
154
  if isinstance(data, (str, Path)):
156
155
  subtitle_data = _handle_string_or_path_data(data)
@@ -15,12 +15,14 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  from enum import Enum, EnumMeta
18
- from typing import Any, Iterable, Sequence, overload
18
+ from typing import TYPE_CHECKING, Any, Iterable, Sequence, overload
19
19
 
20
20
  from streamlit import type_util
21
21
  from streamlit.proto.LabelVisibilityMessage_pb2 import LabelVisibilityMessage
22
22
  from streamlit.runtime.state.common import RegisterWidgetResult
23
- from streamlit.type_util import T
23
+
24
+ if TYPE_CHECKING:
25
+ from streamlit.type_util import T
24
26
 
25
27
 
26
28
  def get_label_visibility_proto_value(
@@ -43,8 +45,7 @@ def maybe_coerce_enum(
43
45
  register_widget_result: RegisterWidgetResult[Enum],
44
46
  options: type[Enum],
45
47
  opt_sequence: Sequence[Any],
46
- ) -> RegisterWidgetResult[Enum]:
47
- ...
48
+ ) -> RegisterWidgetResult[Enum]: ...
48
49
 
49
50
 
50
51
  @overload
@@ -52,8 +53,7 @@ def maybe_coerce_enum(
52
53
  register_widget_result: RegisterWidgetResult[T],
53
54
  options: type_util.OptionSequence[T],
54
55
  opt_sequence: Sequence[T],
55
- ) -> RegisterWidgetResult[T]:
56
- ...
56
+ ) -> RegisterWidgetResult[T]: ...
57
57
 
58
58
 
59
59
  def maybe_coerce_enum(register_widget_result, options, opt_sequence):
@@ -86,8 +86,7 @@ def maybe_coerce_enum_sequence(
86
86
  register_widget_result: RegisterWidgetResult[list[T]],
87
87
  options: type_util.OptionSequence[T],
88
88
  opt_sequence: Sequence[T],
89
- ) -> RegisterWidgetResult[list[T]]:
90
- ...
89
+ ) -> RegisterWidgetResult[list[T]]: ...
91
90
 
92
91
 
93
92
  @overload
@@ -95,8 +94,7 @@ def maybe_coerce_enum_sequence(
95
94
  register_widget_result: RegisterWidgetResult[tuple[T, T]],
96
95
  options: type_util.OptionSequence[T],
97
96
  opt_sequence: Sequence[T],
98
- ) -> RegisterWidgetResult[tuple[T, T]]:
99
- ...
97
+ ) -> RegisterWidgetResult[tuple[T, T]]: ...
100
98
 
101
99
 
102
100
  def maybe_coerce_enum_sequence(register_widget_result, options, opt_sequence):
@@ -279,15 +279,13 @@ class PlotlyMixin:
279
279
  theme: Literal["streamlit"] | None = "streamlit",
280
280
  key: Key | None = None,
281
281
  on_select: Literal["ignore"], # No default value here to make it work with mypy
282
- selection_mode: SelectionMode
283
- | Iterable[SelectionMode] = (
282
+ selection_mode: SelectionMode | Iterable[SelectionMode] = (
284
283
  "points",
285
284
  "box",
286
285
  "lasso",
287
286
  ),
288
287
  **kwargs: Any,
289
- ) -> DeltaGenerator:
290
- ...
288
+ ) -> DeltaGenerator: ...
291
289
 
292
290
  @overload
293
291
  def plotly_chart(
@@ -298,15 +296,13 @@ class PlotlyMixin:
298
296
  theme: Literal["streamlit"] | None = "streamlit",
299
297
  key: Key | None = None,
300
298
  on_select: Literal["rerun"] | WidgetCallback = "rerun",
301
- selection_mode: SelectionMode
302
- | Iterable[SelectionMode] = (
299
+ selection_mode: SelectionMode | Iterable[SelectionMode] = (
303
300
  "points",
304
301
  "box",
305
302
  "lasso",
306
303
  ),
307
304
  **kwargs: Any,
308
- ) -> PlotlyState:
309
- ...
305
+ ) -> PlotlyState: ...
310
306
 
311
307
  @gather_metrics("plotly_chart")
312
308
  def plotly_chart(
@@ -317,8 +313,7 @@ class PlotlyMixin:
317
313
  theme: Literal["streamlit"] | None = "streamlit",
318
314
  key: Key | None = None,
319
315
  on_select: Literal["rerun", "ignore"] | WidgetCallback = "ignore",
320
- selection_mode: SelectionMode
321
- | Iterable[SelectionMode] = (
316
+ selection_mode: SelectionMode | Iterable[SelectionMode] = (
322
317
  "points",
323
318
  "box",
324
319
  "lasso",
@@ -134,7 +134,6 @@ def marshall(
134
134
  **kwargs: Any,
135
135
  ) -> None:
136
136
  try:
137
- import matplotlib
138
137
  import matplotlib.pyplot as plt
139
138
 
140
139
  plt.ioff()
@@ -20,16 +20,16 @@ from streamlit.errors import StreamlitAPIException
20
20
  from streamlit.proto.Toast_pb2 import Toast as ToastProto
21
21
  from streamlit.runtime.metrics_util import gather_metrics
22
22
  from streamlit.string_util import clean_text, validate_icon_or_emoji
23
- from streamlit.type_util import SupportsStr
24
23
 
25
24
  if TYPE_CHECKING:
26
25
  from streamlit.delta_generator import DeltaGenerator
26
+ from streamlit.type_util import SupportsStr
27
27
 
28
28
 
29
29
  def validate_text(toast_text: SupportsStr) -> SupportsStr:
30
30
  if str(toast_text) == "":
31
31
  raise StreamlitAPIException(
32
- f"Toast body cannot be blank - please provide a message."
32
+ "Toast body cannot be blank - please provide a message."
33
33
  )
34
34
  else:
35
35
  return toast_text