streamlit-nightly 1.36.1.dev20240703__py2.py3-none-any.whl → 1.36.1.dev20240704__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 (34) hide show
  1. streamlit/components/v1/component_arrow.py +6 -6
  2. streamlit/dataframe_util.py +181 -132
  3. streamlit/delta_generator.py +1 -1
  4. streamlit/elements/arrow.py +14 -37
  5. streamlit/elements/lib/built_in_chart_utils.py +3 -10
  6. streamlit/elements/lib/pandas_styler_utils.py +3 -1
  7. streamlit/elements/lib/policies.py +41 -7
  8. streamlit/elements/map.py +2 -13
  9. streamlit/elements/plotly_chart.py +10 -11
  10. streamlit/elements/vega_charts.py +16 -29
  11. streamlit/elements/widgets/button.py +16 -14
  12. streamlit/elements/widgets/camera_input.py +8 -8
  13. streamlit/elements/widgets/chat.py +8 -10
  14. streamlit/elements/widgets/checkbox.py +6 -9
  15. streamlit/elements/widgets/color_picker.py +7 -8
  16. streamlit/elements/widgets/data_editor.py +10 -12
  17. streamlit/elements/widgets/file_uploader.py +8 -8
  18. streamlit/elements/widgets/multiselect.py +7 -8
  19. streamlit/elements/widgets/number_input.py +6 -9
  20. streamlit/elements/widgets/radio.py +7 -8
  21. streamlit/elements/widgets/select_slider.py +7 -6
  22. streamlit/elements/widgets/selectbox.py +7 -8
  23. streamlit/elements/widgets/slider.py +7 -8
  24. streamlit/elements/widgets/text_widgets.py +13 -12
  25. streamlit/elements/widgets/time_widgets.py +11 -14
  26. streamlit/elements/write.py +4 -12
  27. streamlit/runtime/caching/cache_utils.py +2 -5
  28. streamlit/testing/v1/element_tree.py +2 -2
  29. {streamlit_nightly-1.36.1.dev20240703.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/METADATA +1 -1
  30. {streamlit_nightly-1.36.1.dev20240703.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/RECORD +34 -34
  31. {streamlit_nightly-1.36.1.dev20240703.data → streamlit_nightly-1.36.1.dev20240704.data}/scripts/streamlit.cmd +0 -0
  32. {streamlit_nightly-1.36.1.dev20240703.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/WHEEL +0 -0
  33. {streamlit_nightly-1.36.1.dev20240703.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/entry_points.txt +0 -0
  34. {streamlit_nightly-1.36.1.dev20240703.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/top_level.txt +0 -0
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import TYPE_CHECKING, Any, Final
17
+ from typing import TYPE_CHECKING, Any, Final, Sequence
18
18
 
19
19
  from streamlit import config, errors, logger, runtime
20
20
  from streamlit.elements.form import is_in_form
@@ -30,7 +30,8 @@ _LOGGER: Final = logger.get_logger(__name__)
30
30
 
31
31
 
32
32
  def check_callback_rules(dg: DeltaGenerator, on_change: WidgetCallback | None) -> None:
33
- """Ensures that widgets other than `st.form_submit` within a form don't have an on_change callback set.
33
+ """Ensures that widgets other than `st.form_submit_button` within a form don't have
34
+ an on_change callback set.
34
35
 
35
36
  Raises
36
37
  ------
@@ -51,9 +52,11 @@ _shown_default_value_warning: bool = False
51
52
  def check_session_state_rules(
52
53
  default_value: Any, key: str | None, writes_allowed: bool = True
53
54
  ) -> None:
54
- """Ensures that no values are set for widgets with the given key when writing is not allowed.
55
+ """Ensures that no values are set for widgets with the given key when writing
56
+ is not allowed.
55
57
 
56
- Additionally, if `global.disableWidgetStateDuplicationWarning` is False a warning is shown when a widget has a default value but its value is also set via session state.
58
+ Additionally, if `global.disableWidgetStateDuplicationWarning` is False a warning is
59
+ shown when a widget has a default value but its value is also set via session state.
57
60
 
58
61
  Raises
59
62
  ------
@@ -71,7 +74,8 @@ def check_session_state_rules(
71
74
 
72
75
  if not writes_allowed:
73
76
  raise StreamlitAPIException(
74
- f'Values for the widget with key "{key}" cannot be set using `st.session_state`.'
77
+ f"Values for the widget with key '{key}' cannot be set using"
78
+ " `st.session_state`."
75
79
  )
76
80
 
77
81
  if (
@@ -126,6 +130,15 @@ _fragment_writes_widget_to_outside_error = (
126
130
 
127
131
 
128
132
  def check_fragment_path_policy(dg: DeltaGenerator):
133
+ """Ensures that the current widget is not written outside of the
134
+ fragment's delta path.
135
+
136
+ Should be called by ever element that acts as a widget.
137
+ We don't allow writing widgets from within a widget to the outside path
138
+ because it can lead to unexpected behavior. For elements, this is okay
139
+ because they do not trigger a re-run.
140
+ """
141
+
129
142
  ctx = get_script_run_ctx()
130
143
  # Check is only relevant for fragments
131
144
  if ctx is None or ctx.current_fragment_id is None:
@@ -138,16 +151,37 @@ def check_fragment_path_policy(dg: DeltaGenerator):
138
151
 
139
152
  current_cursor_delta_path = current_cursor.delta_path
140
153
 
141
- # the elements delta path cannot be smaller than the fragment's delta path if it is inside of the fragment
154
+ # the elements delta path cannot be smaller than the fragment's delta path if it is
155
+ # inside of the fragment
142
156
  if len(current_cursor_delta_path) < len(current_fragment_delta_path):
143
157
  raise StreamlitAPIException(_fragment_writes_widget_to_outside_error)
144
158
 
145
- # all path indices of the fragment-path must occur in the inner-elements delta path, otherwise it is outside of the fragment container
159
+ # all path indices of the fragment-path must occur in the inner-elements delta path,
160
+ # otherwise it is outside of the fragment container
146
161
  for index, path_index in enumerate(current_fragment_delta_path):
147
162
  if current_cursor_delta_path[index] != path_index:
148
163
  raise StreamlitAPIException(_fragment_writes_widget_to_outside_error)
149
164
 
150
165
 
166
+ def check_widget_policies(
167
+ dg: DeltaGenerator,
168
+ key: str | None,
169
+ on_change: WidgetCallback | None = None,
170
+ *,
171
+ default_value: Sequence[Any] | Any | None = None,
172
+ writes_allowed: bool = True,
173
+ enable_check_callback_rules: bool = True,
174
+ ):
175
+ """Check all widget policies for the given DeltaGenerator."""
176
+ check_fragment_path_policy(dg)
177
+ check_cache_replay_rules()
178
+ if enable_check_callback_rules:
179
+ check_callback_rules(dg, on_change)
180
+ check_session_state_rules(
181
+ default_value=default_value, key=key, writes_allowed=writes_allowed
182
+ )
183
+
184
+
151
185
  def maybe_raise_label_warnings(label: str | None, label_visibility: str | None):
152
186
  if not label:
153
187
  _LOGGER.warning(
streamlit/elements/map.py CHANGED
@@ -19,9 +19,7 @@ from __future__ import annotations
19
19
  import copy
20
20
  import hashlib
21
21
  import json
22
- from typing import TYPE_CHECKING, Any, Collection, Dict, Final, Iterable, Union, cast
23
-
24
- from typing_extensions import TypeAlias
22
+ from typing import TYPE_CHECKING, Any, Collection, Final, cast
25
23
 
26
24
  import streamlit.elements.deck_gl_json_chart as deck_gl_json_chart
27
25
  from streamlit import config, dataframe_util
@@ -33,19 +31,10 @@ from streamlit.util import HASHLIB_KWARGS
33
31
 
34
32
  if TYPE_CHECKING:
35
33
  from pandas import DataFrame
36
- from pandas.io.formats.style import Styler
37
34
 
35
+ from streamlit.dataframe_util import Data
38
36
  from streamlit.delta_generator import DeltaGenerator
39
37
 
40
-
41
- Data: TypeAlias = Union[
42
- "DataFrame",
43
- "Styler",
44
- Iterable[Any],
45
- Dict[Any, Any],
46
- None,
47
- ]
48
-
49
38
  # Map used as the basis for st.map.
50
39
  _DEFAULT_MAP: Final[dict[str, Any]] = dict(deck_gl_json_chart.EMPTY_MAP)
51
40
 
@@ -38,12 +38,7 @@ from streamlit import type_util
38
38
  from streamlit.deprecation_util import show_deprecation_warning
39
39
  from streamlit.elements.form import current_form_id
40
40
  from streamlit.elements.lib.event_utils import AttributeDictionary
41
- from streamlit.elements.lib.policies import (
42
- check_cache_replay_rules,
43
- check_callback_rules,
44
- check_fragment_path_policy,
45
- check_session_state_rules,
46
- )
41
+ from streamlit.elements.lib.policies import check_widget_policies
47
42
  from streamlit.elements.lib.streamlit_plotly_theme import (
48
43
  configure_streamlit_plotly_theme,
49
44
  )
@@ -467,11 +462,15 @@ class PlotlyMixin:
467
462
  if is_selection_activated:
468
463
  # Run some checks that are only relevant when selections are activated
469
464
 
470
- check_fragment_path_policy(self.dg)
471
- check_cache_replay_rules()
472
- if callable(on_select):
473
- check_callback_rules(self.dg, on_select)
474
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
465
+ is_callback = callable(on_select)
466
+ check_widget_policies(
467
+ self.dg,
468
+ key,
469
+ on_change=cast(WidgetCallback, on_select) if is_callback else None,
470
+ default_value=None,
471
+ writes_allowed=False,
472
+ enable_check_callback_rules=is_callback,
473
+ )
475
474
 
476
475
  if type_util.is_type(figure_or_data, "matplotlib.figure.Figure"):
477
476
  # Convert matplotlib figure to plotly figure:
@@ -44,12 +44,7 @@ from streamlit.elements.lib.built_in_chart_utils import (
44
44
  generate_chart,
45
45
  )
46
46
  from streamlit.elements.lib.event_utils import AttributeDictionary
47
- from streamlit.elements.lib.policies import (
48
- check_cache_replay_rules,
49
- check_callback_rules,
50
- check_fragment_path_policy,
51
- check_session_state_rules,
52
- )
47
+ from streamlit.elements.lib.policies import check_widget_policies
53
48
  from streamlit.elements.lib.utils import Key, to_key
54
49
  from streamlit.errors import StreamlitAPIException
55
50
  from streamlit.proto.ArrowVegaLiteChart_pb2 import (
@@ -57,7 +52,7 @@ from streamlit.proto.ArrowVegaLiteChart_pb2 import (
57
52
  )
58
53
  from streamlit.runtime.metrics_util import gather_metrics
59
54
  from streamlit.runtime.scriptrunner import get_script_run_ctx
60
- from streamlit.runtime.state import register_widget
55
+ from streamlit.runtime.state import WidgetCallback, register_widget
61
56
  from streamlit.runtime.state.common import compute_widget_id
62
57
  from streamlit.util import HASHLIB_KWARGS
63
58
 
@@ -65,9 +60,8 @@ if TYPE_CHECKING:
65
60
  import altair as alt
66
61
 
67
62
  from streamlit.color_util import Color
63
+ from streamlit.dataframe_util import Data
68
64
  from streamlit.delta_generator import DeltaGenerator
69
- from streamlit.elements.arrow import Data
70
- from streamlit.runtime.state import WidgetCallback
71
65
 
72
66
  # See https://vega.github.io/vega-lite/docs/encoding.html
73
67
  _CHANNELS: Final = {
@@ -275,17 +269,6 @@ def _prepare_vega_lite_spec(
275
269
  return spec
276
270
 
277
271
 
278
- def _serialize_data(data: Any) -> bytes:
279
- """Serialize the any type of data structure to Arrow IPC format (bytes)."""
280
- import pyarrow as pa
281
-
282
- if isinstance(data, pa.Table):
283
- return dataframe_util.pyarrow_table_to_bytes(data)
284
-
285
- df = dataframe_util.convert_anything_to_pandas_df(data)
286
- return dataframe_util.data_frame_to_bytes(df)
287
-
288
-
289
272
  def _marshall_chart_data(
290
273
  proto: ArrowVegaLiteChartProto,
291
274
  spec: VegaLiteSpec,
@@ -308,11 +291,11 @@ def _marshall_chart_data(
308
291
  # We just need to pass the data information into the correct proto fields.
309
292
 
310
293
  # TODO(lukasmasuch): Are there any other cases where we need to serialize the data
311
- # or can we remove the _serialize_data here?
294
+ # or can we remove the convert_anything_to_arrow_bytes here?
312
295
  dataset.data.data = (
313
296
  dataset_data
314
297
  if isinstance(dataset_data, bytes)
315
- else _serialize_data(dataset_data)
298
+ else dataframe_util.convert_anything_to_arrow_bytes(dataset_data)
316
299
  )
317
300
  del spec["datasets"]
318
301
 
@@ -333,7 +316,7 @@ def _marshall_chart_data(
333
316
  del spec["data"]
334
317
 
335
318
  if data is not None:
336
- proto.data.data = _serialize_data(data)
319
+ proto.data.data = dataframe_util.convert_anything_to_arrow_bytes(data)
337
320
 
338
321
 
339
322
  def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> VegaLiteSpec:
@@ -355,7 +338,7 @@ def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> VegaLiteSpec:
355
338
  """
356
339
  # Already serialize the data to be able to create a stable
357
340
  # dataset name:
358
- data_bytes = _serialize_data(data)
341
+ data_bytes = dataframe_util.convert_anything_to_arrow_bytes(data)
359
342
  # Use the md5 hash of the data as the name:
360
343
  h = hashlib.new("md5", **HASHLIB_KWARGS)
361
344
  h.update(str(data_bytes).encode("utf-8"))
@@ -1788,11 +1771,15 @@ class VegaChartsMixin:
1788
1771
  if is_selection_activated:
1789
1772
  # Run some checks that are only relevant when selections are activated
1790
1773
 
1791
- check_fragment_path_policy(self.dg)
1792
- check_cache_replay_rules()
1793
- if callable(on_select):
1794
- check_callback_rules(self.dg, on_select)
1795
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
1774
+ is_callback = callable(on_select)
1775
+ check_widget_policies(
1776
+ self.dg,
1777
+ key,
1778
+ on_change=cast(WidgetCallback, on_select) if is_callback else None,
1779
+ default_value=None,
1780
+ writes_allowed=False,
1781
+ enable_check_callback_rules=is_callback,
1782
+ )
1796
1783
 
1797
1784
  # Support passing data inside spec['datasets'] and spec['data'].
1798
1785
  # (The data gets pulled out of the spec dict later on.)
@@ -24,12 +24,7 @@ from typing_extensions import TypeAlias
24
24
 
25
25
  from streamlit import runtime
26
26
  from streamlit.elements.form import current_form_id, is_in_form
27
- from streamlit.elements.lib.policies import (
28
- check_cache_replay_rules,
29
- check_callback_rules,
30
- check_fragment_path_policy,
31
- check_session_state_rules,
32
- )
27
+ from streamlit.elements.lib.policies import check_widget_policies
33
28
  from streamlit.elements.lib.utils import Key, to_key
34
29
  from streamlit.errors import StreamlitAPIException
35
30
  from streamlit.file_util import get_main_script_directory, normalize_path_join
@@ -600,9 +595,13 @@ class ButtonMixin:
600
595
  ) -> bool:
601
596
  key = to_key(key)
602
597
 
603
- check_cache_replay_rules()
604
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
605
- check_callback_rules(self.dg, on_click)
598
+ check_widget_policies(
599
+ self.dg,
600
+ key,
601
+ on_click,
602
+ default_value=None,
603
+ writes_allowed=False,
604
+ )
606
605
 
607
606
  id = compute_widget_id(
608
607
  "download_button",
@@ -764,11 +763,14 @@ class ButtonMixin:
764
763
  ) -> bool:
765
764
  key = to_key(key)
766
765
 
767
- check_fragment_path_policy(self.dg)
768
- if not is_form_submitter:
769
- check_callback_rules(self.dg, on_click)
770
- check_cache_replay_rules()
771
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
766
+ check_widget_policies(
767
+ self.dg,
768
+ key,
769
+ on_click,
770
+ default_value=None,
771
+ writes_allowed=False,
772
+ enable_check_callback_rules=not is_form_submitter,
773
+ )
772
774
 
773
775
  id = compute_widget_id(
774
776
  "button",
@@ -22,10 +22,7 @@ from typing_extensions import TypeAlias
22
22
 
23
23
  from streamlit.elements.form import current_form_id
24
24
  from streamlit.elements.lib.policies import (
25
- check_cache_replay_rules,
26
- check_callback_rules,
27
- check_fragment_path_policy,
28
- check_session_state_rules,
25
+ check_widget_policies,
29
26
  maybe_raise_label_warnings,
30
27
  )
31
28
  from streamlit.elements.lib.utils import (
@@ -206,10 +203,13 @@ class CameraInputMixin:
206
203
  ) -> UploadedFile | None:
207
204
  key = to_key(key)
208
205
 
209
- check_fragment_path_policy(self.dg)
210
- check_cache_replay_rules()
211
- check_callback_rules(self.dg, on_change)
212
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
206
+ check_widget_policies(
207
+ self.dg,
208
+ key,
209
+ on_change,
210
+ default_value=None,
211
+ writes_allowed=False,
212
+ )
213
213
  maybe_raise_label_warnings(label, label_visibility)
214
214
 
215
215
  id = compute_widget_id(
@@ -21,12 +21,7 @@ from typing import TYPE_CHECKING, Literal, cast
21
21
  from streamlit import runtime
22
22
  from streamlit.elements.form import is_in_form
23
23
  from streamlit.elements.image import AtomicImage, WidthBehaviour, image_to_url
24
- from streamlit.elements.lib.policies import (
25
- check_cache_replay_rules,
26
- check_callback_rules,
27
- check_fragment_path_policy,
28
- check_session_state_rules,
29
- )
24
+ from streamlit.elements.lib.policies import check_widget_policies
30
25
  from streamlit.elements.lib.utils import Key, to_key
31
26
  from streamlit.errors import StreamlitAPIException
32
27
  from streamlit.proto.Block_pb2 import Block as BlockProto
@@ -317,10 +312,13 @@ class ChatMixin:
317
312
  default = ""
318
313
  key = to_key(key)
319
314
 
320
- check_fragment_path_policy(self.dg)
321
- check_cache_replay_rules()
322
- check_callback_rules(self.dg, on_submit)
323
- check_session_state_rules(default_value=default, key=key, writes_allowed=False)
315
+ check_widget_policies(
316
+ self.dg,
317
+ key,
318
+ on_submit,
319
+ default_value=default,
320
+ writes_allowed=False,
321
+ )
324
322
 
325
323
  ctx = get_script_run_ctx()
326
324
  id = compute_widget_id(
@@ -20,10 +20,7 @@ from typing import TYPE_CHECKING, cast
20
20
 
21
21
  from streamlit.elements.form import current_form_id
22
22
  from streamlit.elements.lib.policies import (
23
- check_cache_replay_rules,
24
- check_callback_rules,
25
- check_fragment_path_policy,
26
- check_session_state_rules,
23
+ check_widget_policies,
27
24
  maybe_raise_label_warnings,
28
25
  )
29
26
  from streamlit.elements.lib.utils import (
@@ -288,11 +285,11 @@ class CheckboxMixin:
288
285
  ) -> bool:
289
286
  key = to_key(key)
290
287
 
291
- check_fragment_path_policy(self.dg)
292
- check_cache_replay_rules()
293
- check_callback_rules(self.dg, on_change)
294
- check_session_state_rules(
295
- default_value=None if value is False else value, key=key
288
+ check_widget_policies(
289
+ self.dg,
290
+ key,
291
+ on_change,
292
+ default_value=None if value is False else value,
296
293
  )
297
294
  maybe_raise_label_warnings(label, label_visibility)
298
295
 
@@ -21,10 +21,7 @@ from typing import TYPE_CHECKING, cast
21
21
 
22
22
  from streamlit.elements.form import current_form_id
23
23
  from streamlit.elements.lib.policies import (
24
- check_cache_replay_rules,
25
- check_callback_rules,
26
- check_fragment_path_policy,
27
- check_session_state_rules,
24
+ check_widget_policies,
28
25
  maybe_raise_label_warnings,
29
26
  )
30
27
  from streamlit.elements.lib.utils import (
@@ -182,10 +179,12 @@ class ColorPickerMixin:
182
179
  ) -> str:
183
180
  key = to_key(key)
184
181
 
185
- check_fragment_path_policy(self.dg)
186
- check_cache_replay_rules()
187
- check_callback_rules(self.dg, on_change)
188
- check_session_state_rules(default_value=value, key=key)
182
+ check_widget_policies(
183
+ self.dg,
184
+ key,
185
+ on_change,
186
+ default_value=value,
187
+ )
189
188
  maybe_raise_label_warnings(label, label_visibility)
190
189
 
191
190
  id = compute_widget_id(
@@ -54,12 +54,7 @@ from streamlit.elements.lib.column_config_utils import (
54
54
  update_column_config,
55
55
  )
56
56
  from streamlit.elements.lib.pandas_styler_utils import marshall_styler
57
- from streamlit.elements.lib.policies import (
58
- check_cache_replay_rules,
59
- check_callback_rules,
60
- check_fragment_path_policy,
61
- check_session_state_rules,
62
- )
57
+ from streamlit.elements.lib.policies import check_widget_policies
63
58
  from streamlit.elements.lib.utils import Key, to_key
64
59
  from streamlit.errors import StreamlitAPIException
65
60
  from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
@@ -786,10 +781,13 @@ class DataEditorMixin:
786
781
 
787
782
  key = to_key(key)
788
783
 
789
- check_fragment_path_policy(self.dg)
790
- check_cache_replay_rules()
791
- check_callback_rules(self.dg, on_change)
792
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
784
+ check_widget_policies(
785
+ self.dg,
786
+ key,
787
+ on_change,
788
+ default_value=None,
789
+ writes_allowed=False,
790
+ )
793
791
 
794
792
  if column_order is not None:
795
793
  column_order = list(column_order)
@@ -856,7 +854,7 @@ class DataEditorMixin:
856
854
  # Throws an exception if any of the configured types are incompatible.
857
855
  _check_type_compatibilities(data_df, column_config_mapping, dataframe_schema)
858
856
 
859
- arrow_bytes = dataframe_util.pyarrow_table_to_bytes(arrow_table)
857
+ arrow_bytes = dataframe_util.convert_arrow_table_to_arrow_bytes(arrow_table)
860
858
 
861
859
  # We want to do this as early as possible to avoid introducing nondeterminism,
862
860
  # but it isn't clear how much processing is needed to have the data in a
@@ -937,7 +935,7 @@ class DataEditorMixin:
937
935
 
938
936
  _apply_dataframe_edits(data_df, widget_state.value, dataframe_schema)
939
937
  self.dg._enqueue("arrow_data_frame", proto)
940
- return dataframe_util.convert_df_to_data_format(data_df, data_format)
938
+ return dataframe_util.convert_pandas_df_to_data_format(data_df, data_format)
941
939
 
942
940
  @property
943
941
  def dg(self) -> DeltaGenerator:
@@ -23,10 +23,7 @@ from typing_extensions import TypeAlias
23
23
  from streamlit import config
24
24
  from streamlit.elements.form import current_form_id
25
25
  from streamlit.elements.lib.policies import (
26
- check_cache_replay_rules,
27
- check_callback_rules,
28
- check_fragment_path_policy,
29
- check_session_state_rules,
26
+ check_widget_policies,
30
27
  maybe_raise_label_warnings,
31
28
  )
32
29
  from streamlit.elements.lib.utils import (
@@ -405,10 +402,13 @@ class FileUploaderMixin:
405
402
  ) -> UploadedFile | list[UploadedFile] | None:
406
403
  key = to_key(key)
407
404
 
408
- check_fragment_path_policy(self.dg)
409
- check_cache_replay_rules()
410
- check_callback_rules(self.dg, on_change)
411
- check_session_state_rules(default_value=None, key=key, writes_allowed=False)
405
+ check_widget_policies(
406
+ self.dg,
407
+ key,
408
+ on_change,
409
+ default_value=None,
410
+ writes_allowed=False,
411
+ )
412
412
  maybe_raise_label_warnings(label, label_visibility)
413
413
 
414
414
  id = compute_widget_id(
@@ -21,10 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast, overlo
21
21
  from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
22
22
  from streamlit.elements.form import current_form_id
23
23
  from streamlit.elements.lib.policies import (
24
- check_cache_replay_rules,
25
- check_callback_rules,
26
- check_fragment_path_policy,
27
- check_session_state_rules,
24
+ check_widget_policies,
28
25
  maybe_raise_label_warnings,
29
26
  )
30
27
  from streamlit.elements.lib.utils import (
@@ -291,10 +288,12 @@ class MultiSelectMixin:
291
288
  ) -> list[T]:
292
289
  key = to_key(key)
293
290
 
294
- check_fragment_path_policy(self.dg)
295
- check_cache_replay_rules()
296
- check_callback_rules(self.dg, on_change)
297
- check_session_state_rules(default_value=default, key=key)
291
+ check_widget_policies(
292
+ self.dg,
293
+ key,
294
+ on_change,
295
+ default_value=default,
296
+ )
298
297
  maybe_raise_label_warnings(label, label_visibility)
299
298
 
300
299
  opt = convert_anything_to_sequence(options)
@@ -23,10 +23,7 @@ from typing_extensions import TypeAlias
23
23
 
24
24
  from streamlit.elements.form import current_form_id
25
25
  from streamlit.elements.lib.policies import (
26
- check_cache_replay_rules,
27
- check_callback_rules,
28
- check_fragment_path_policy,
29
- check_session_state_rules,
26
+ check_widget_policies,
30
27
  maybe_raise_label_warnings,
31
28
  )
32
29
  from streamlit.elements.lib.utils import (
@@ -289,11 +286,11 @@ class NumberInputMixin:
289
286
  ) -> Number | None:
290
287
  key = to_key(key)
291
288
 
292
- check_fragment_path_policy(self.dg)
293
- check_cache_replay_rules()
294
- check_callback_rules(self.dg, on_change)
295
- check_session_state_rules(
296
- default_value=value if value != "min" else None, key=key
289
+ check_widget_policies(
290
+ self.dg,
291
+ key,
292
+ on_change,
293
+ default_value=value if value != "min" else None,
297
294
  )
298
295
  maybe_raise_label_warnings(label, label_visibility)
299
296
 
@@ -21,10 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast
21
21
  from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
22
22
  from streamlit.elements.form import current_form_id
23
23
  from streamlit.elements.lib.policies import (
24
- check_cache_replay_rules,
25
- check_callback_rules,
26
- check_fragment_path_policy,
27
- check_session_state_rules,
24
+ check_widget_policies,
28
25
  maybe_raise_label_warnings,
29
26
  )
30
27
  from streamlit.elements.lib.utils import (
@@ -257,10 +254,12 @@ class RadioMixin:
257
254
  ) -> T | None:
258
255
  key = to_key(key)
259
256
 
260
- check_fragment_path_policy(self.dg)
261
- check_cache_replay_rules()
262
- check_callback_rules(self.dg, on_change)
263
- check_session_state_rules(default_value=None if index == 0 else index, key=key)
257
+ check_widget_policies(
258
+ self.dg,
259
+ key,
260
+ on_change,
261
+ default_value=None if index == 0 else index,
262
+ )
264
263
  maybe_raise_label_warnings(label, label_visibility)
265
264
 
266
265
  opt = convert_anything_to_sequence(options)
@@ -23,9 +23,7 @@ from typing_extensions import TypeGuard
23
23
  from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
24
24
  from streamlit.elements.form import current_form_id
25
25
  from streamlit.elements.lib.policies import (
26
- check_cache_replay_rules,
27
- check_callback_rules,
28
- check_session_state_rules,
26
+ check_widget_policies,
29
27
  maybe_raise_label_warnings,
30
28
  )
31
29
  from streamlit.elements.lib.utils import (
@@ -262,9 +260,12 @@ class SelectSliderMixin:
262
260
  ) -> T | tuple[T, T]:
263
261
  key = to_key(key)
264
262
 
265
- check_cache_replay_rules()
266
- check_callback_rules(self.dg, on_change)
267
- check_session_state_rules(default_value=value, key=key)
263
+ check_widget_policies(
264
+ self.dg,
265
+ key,
266
+ on_change,
267
+ default_value=value,
268
+ )
268
269
  maybe_raise_label_warnings(label, label_visibility)
269
270
 
270
271
  opt = convert_anything_to_sequence(options)
@@ -20,10 +20,7 @@ from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast
20
20
  from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
21
21
  from streamlit.elements.form import current_form_id
22
22
  from streamlit.elements.lib.policies import (
23
- check_cache_replay_rules,
24
- check_callback_rules,
25
- check_fragment_path_policy,
26
- check_session_state_rules,
23
+ check_widget_policies,
27
24
  maybe_raise_label_warnings,
28
25
  )
29
26
  from streamlit.elements.lib.utils import (
@@ -237,10 +234,12 @@ class SelectboxMixin:
237
234
  ) -> T | None:
238
235
  key = to_key(key)
239
236
 
240
- check_fragment_path_policy(self.dg)
241
- check_cache_replay_rules()
242
- check_callback_rules(self.dg, on_change)
243
- check_session_state_rules(default_value=None if index == 0 else index, key=key)
237
+ check_widget_policies(
238
+ self.dg,
239
+ key,
240
+ on_change,
241
+ default_value=None if index == 0 else index,
242
+ )
244
243
  maybe_raise_label_warnings(label, label_visibility)
245
244
 
246
245
  opt = convert_anything_to_sequence(options)