streamlit-nightly 1.32.3.dev20240402__py2.py3-none-any.whl → 1.32.3.dev20240403__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.
@@ -119,9 +119,9 @@ ARROW_DELTA_TYPES_THAT_MELT_DATAFRAMES: Final = (
119
119
  Value = TypeVar("Value")
120
120
  DG = TypeVar("DG", bound="DeltaGenerator")
121
121
 
122
- # Type aliases for Parent Block Types
122
+ # Type aliases for Ancestor Block Types
123
123
  BlockType = str
124
- ParentBlockTypes = Iterable[BlockType]
124
+ AncestorBlockTypes = Iterable[BlockType]
125
125
 
126
126
 
127
127
  _use_warning_has_been_displayed: bool = False
@@ -348,7 +348,7 @@ class DeltaGenerator(
348
348
  message = (
349
349
  f"Method `{name}()` does not exist for "
350
350
  "`DeltaGenerator` objects. Did you mean "
351
- "`st.{name}()`?"
351
+ f"`st.{name}()`?"
352
352
  )
353
353
  else:
354
354
  message = f"`{name}()` is not a valid Streamlit command."
@@ -368,18 +368,27 @@ class DeltaGenerator(
368
368
  return dg
369
369
 
370
370
  @property
371
- def _parent_block_types(self) -> ParentBlockTypes:
372
- """Iterate all the block types used by this DeltaGenerator and all
373
- its ancestor DeltaGenerators.
374
- """
371
+ def _ancestors(self) -> Iterable["DeltaGenerator"]:
375
372
  current_dg: DeltaGenerator | None = self
376
373
  while current_dg is not None:
377
- if current_dg._block_type is not None:
378
- yield current_dg._block_type
374
+ yield current_dg
379
375
  current_dg = current_dg._parent
380
376
 
381
- def _count_num_of_parent_columns(self, parent_block_types: ParentBlockTypes) -> int:
382
- return sum(1 for parent_block in parent_block_types if parent_block == "column")
377
+ @property
378
+ def _ancestor_block_types(self) -> AncestorBlockTypes:
379
+ """Iterate all the block types used by this DeltaGenerator and all
380
+ its ancestor DeltaGenerators.
381
+ """
382
+ for a in self._ancestors:
383
+ if a._block_type is not None:
384
+ yield a._block_type
385
+
386
+ def _count_num_of_parent_columns(
387
+ self, ancestor_block_types: AncestorBlockTypes
388
+ ) -> int:
389
+ return sum(
390
+ 1 for ancestor_block in ancestor_block_types if ancestor_block == "column"
391
+ )
383
392
 
384
393
  @property
385
394
  def _cursor(self) -> Cursor | None:
@@ -509,6 +518,15 @@ class DeltaGenerator(
509
518
  """
510
519
  # Operate on the active DeltaGenerator, in case we're in a `with` block.
511
520
  dg = self._active_dg
521
+
522
+ ctx = get_script_run_ctx()
523
+ if ctx and ctx.current_fragment_id and _writes_directly_to_sidebar(dg):
524
+ raise StreamlitAPIException(
525
+ "Calling `st.sidebar` in a function wrapped with `st.experimental_fragment` "
526
+ "is not supported. To write elements to the sidebar with a fragment, "
527
+ "call your fragment function inside a `with st.sidebar` context manager."
528
+ )
529
+
512
530
  # Warn if we're called from within a legacy @st.cache function
513
531
  legacy_caching.maybe_show_cached_st_function_warning(dg, delta_type)
514
532
  # Warn if we're called from within @st.memo or @st.singleton
@@ -587,11 +605,11 @@ class DeltaGenerator(
587
605
  # Prevent nested columns & expanders by checking all parents.
588
606
  block_type = block_proto.WhichOneof("type")
589
607
  # Convert the generator to a list, so we can use it multiple times.
590
- parent_block_types = list(dg._parent_block_types)
608
+ ancestor_block_types = list(dg._ancestor_block_types)
591
609
 
592
610
  if block_type == "column":
593
611
  num_of_parent_columns = self._count_num_of_parent_columns(
594
- parent_block_types
612
+ ancestor_block_types
595
613
  )
596
614
  if (
597
615
  self._root_container == RootContainer.SIDEBAR
@@ -604,15 +622,15 @@ class DeltaGenerator(
604
622
  raise StreamlitAPIException(
605
623
  "Columns can only be placed inside other columns up to one level of nesting."
606
624
  )
607
- if block_type == "chat_message" and block_type in frozenset(parent_block_types):
625
+ if block_type == "chat_message" and block_type in ancestor_block_types:
608
626
  raise StreamlitAPIException(
609
627
  "Chat messages cannot nested inside other chat messages."
610
628
  )
611
- if block_type == "expandable" and block_type in frozenset(parent_block_types):
629
+ if block_type == "expandable" and block_type in ancestor_block_types:
612
630
  raise StreamlitAPIException(
613
631
  "Expanders may not be nested inside other expanders."
614
632
  )
615
- if block_type == "popover" and block_type in frozenset(parent_block_types):
633
+ if block_type == "popover" and block_type in ancestor_block_types:
616
634
  raise StreamlitAPIException(
617
635
  "Popovers may not be nested inside other popovers."
618
636
  )
@@ -903,3 +921,9 @@ def _enqueue_message(msg: ForwardMsg_pb2.ForwardMsg) -> None:
903
921
  msg.delta.fragment_id = ctx.current_fragment_id
904
922
 
905
923
  ctx.enqueue(msg)
924
+
925
+
926
+ def _writes_directly_to_sidebar(dg: DG) -> bool:
927
+ in_sidebar = any(a._root_container == RootContainer.SIDEBAR for a in dg._ancestors)
928
+ has_container = bool(len(list(dg._ancestor_block_types)))
929
+ return in_sidebar and not has_container
@@ -85,7 +85,7 @@ def spinner(text: str = "In progress...", *, _cache: bool = False) -> Iterator[N
85
85
  display_message = False
86
86
  with legacy_caching.suppress_cached_st_function_warning():
87
87
  with caching.suppress_cached_st_function_warning():
88
- if "chat_message" in set(message._active_dg._parent_block_types):
88
+ if "chat_message" in set(message._active_dg._ancestor_block_types):
89
89
  # Temporary stale element fix:
90
90
  # For chat messages, we are resetting the spinner placeholder to an
91
91
  # empty container instead of an empty placeholder (st.empty) to have
@@ -316,10 +316,10 @@ class ChatMixin:
316
316
  # Use bottom position if chat input is within the main container
317
317
  # either directly or within a vertical container. If it has any
318
318
  # other container types as parents, we use inline position.
319
- parent_block_types = set(self.dg._active_dg._parent_block_types)
319
+ ancestor_block_types = set(self.dg._active_dg._ancestor_block_types)
320
320
  if (
321
321
  self.dg._active_dg._root_container == RootContainer.MAIN
322
- and not parent_block_types
322
+ and not ancestor_block_types
323
323
  ):
324
324
  position = "bottom"
325
325
  else:
@@ -604,6 +604,14 @@ class SliderMixin:
604
604
  min_value = _date_to_datetime(min_value)
605
605
  max_value = _date_to_datetime(max_value)
606
606
 
607
+ # The frontend will error if the values are equal, so checking here
608
+ # lets us produce a nicer python error message and stack trace.
609
+ if min_value == max_value:
610
+ raise StreamlitAPIException(
611
+ "Slider `min_value` must be less than the `max_value`."
612
+ f"\nThe values were {min_value} and {max_value}."
613
+ )
614
+
607
615
  # Now, convert to microseconds (so we can serialize datetime to a long)
608
616
  if data_type in TIMELIKE_TYPES:
609
617
  # Restore times/datetimes to original timezone (dates are always naive)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.bf304093.css",
4
- "main.js": "./static/js/main.6d659dbc.js",
4
+ "main.js": "./static/js/main.9c129b72.js",
5
5
  "static/js/9336.2d95d840.chunk.js": "./static/js/9336.2d95d840.chunk.js",
6
6
  "static/js/9330.d29313d4.chunk.js": "./static/js/9330.d29313d4.chunk.js",
7
7
  "static/js/7217.d970c074.chunk.js": "./static/js/7217.d970c074.chunk.js",
@@ -152,6 +152,6 @@
152
152
  },
153
153
  "entrypoints": [
154
154
  "static/css/main.bf304093.css",
155
- "static/js/main.6d659dbc.js"
155
+ "static/js/main.9c129b72.js"
156
156
  ]
157
157
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.6d659dbc.js"></script><link href="./static/css/main.bf304093.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon" href="./favicon.png"/><link rel="preload" href="./static/media/SourceSansPro-Regular.0d69e5ff5e92ac64a0c9.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-SemiBold.abed79cd0df1827e18cf.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="./static/media/SourceSansPro-Bold.118dea98980e20a81ced.woff2" as="font" type="font/woff2" crossorigin><title>Streamlit</title><script>window.prerenderReady=!1</script><script defer="defer" src="./static/js/main.9c129b72.js"></script><link href="./static/css/main.bf304093.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>