reflex 0.8.9a1__py3-none-any.whl → 0.8.10__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.

Potentially problematic release.


This version of reflex might be problematic. Click here for more details.

@@ -10,7 +10,7 @@ import functools
10
10
  import inspect
11
11
  import typing
12
12
  from abc import ABC, ABCMeta, abstractmethod
13
- from collections.abc import Callable, Iterator, Mapping, Sequence
13
+ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
14
14
  from dataclasses import _MISSING_TYPE, MISSING
15
15
  from functools import wraps
16
16
  from hashlib import md5
@@ -374,7 +374,7 @@ class BaseComponent(metaclass=BaseComponentMeta):
374
374
  """
375
375
 
376
376
  @abstractmethod
377
- def _get_all_custom_code(self) -> set[str]:
377
+ def _get_all_custom_code(self) -> dict[str, None]:
378
378
  """Get custom code for the component.
379
379
 
380
380
  Returns:
@@ -382,7 +382,7 @@ class BaseComponent(metaclass=BaseComponentMeta):
382
382
  """
383
383
 
384
384
  @abstractmethod
385
- def _get_all_refs(self) -> set[str]:
385
+ def _get_all_refs(self) -> dict[str, None]:
386
386
  """Get the refs for the children of the component.
387
387
 
388
388
  Returns:
@@ -1003,13 +1003,13 @@ class Component(BaseComponent, ABC):
1003
1003
 
1004
1004
  @classmethod
1005
1005
  @functools.cache
1006
- def get_props(cls) -> set[str]:
1006
+ def get_props(cls) -> Iterable[str]:
1007
1007
  """Get the unique fields for the component.
1008
1008
 
1009
1009
  Returns:
1010
1010
  The unique fields.
1011
1011
  """
1012
- return set(cls.get_js_fields())
1012
+ return cls.get_js_fields()
1013
1013
 
1014
1014
  @classmethod
1015
1015
  @functools.cache
@@ -1021,48 +1021,8 @@ class Component(BaseComponent, ABC):
1021
1021
  """
1022
1022
  return set()
1023
1023
 
1024
- @classmethod
1025
- def _are_fields_known(cls) -> bool:
1026
- """Check if all fields are known at compile time. True for most components.
1027
-
1028
- Returns:
1029
- Whether all fields are known at compile time.
1030
- """
1031
- return True
1032
-
1033
- @classmethod
1034
- @functools.cache
1035
- def _get_component_prop_names(cls) -> set[str]:
1036
- """Get the names of the component props. NOTE: This assumes all fields are known.
1037
-
1038
- Returns:
1039
- The names of the component props.
1040
- """
1041
- return {
1042
- name
1043
- for name in cls.get_fields()
1044
- if name in cls.get_props()
1045
- and isinstance(
1046
- field_type := types.value_inside_optional(
1047
- types.get_field_type(cls, name)
1048
- ),
1049
- type,
1050
- )
1051
- and issubclass(field_type, Component)
1052
- }
1053
-
1054
- def _get_components_in_props(self) -> Sequence[BaseComponent]:
1055
- """Get the components in the props.
1056
-
1057
- Returns:
1058
- The components in the props
1059
- """
1060
- if self._are_fields_known():
1061
- return [
1062
- component
1063
- for name in self._get_component_prop_names()
1064
- for component in _components_from(getattr(self, name))
1065
- ]
1024
+ @functools.cached_property
1025
+ def _get_component_prop_property(self) -> Sequence[BaseComponent]:
1066
1026
  return [
1067
1027
  component
1068
1028
  for prop in self.get_props()
@@ -1071,6 +1031,14 @@ class Component(BaseComponent, ABC):
1071
1031
  for component in _components_from(value)
1072
1032
  ]
1073
1033
 
1034
+ def _get_components_in_props(self) -> Sequence[BaseComponent]:
1035
+ """Get the components in the props.
1036
+
1037
+ Returns:
1038
+ The components in the props
1039
+ """
1040
+ return self._get_component_prop_property
1041
+
1074
1042
  @classmethod
1075
1043
  def _validate_children(cls, children: tuple | list):
1076
1044
  from reflex.utils.exceptions import ChildrenTypeError
@@ -1541,19 +1509,19 @@ class Component(BaseComponent, ABC):
1541
1509
  """
1542
1510
  return None
1543
1511
 
1544
- def _get_all_custom_code(self) -> set[str]:
1512
+ def _get_all_custom_code(self) -> dict[str, None]:
1545
1513
  """Get custom code for the component and its children.
1546
1514
 
1547
1515
  Returns:
1548
1516
  The custom code.
1549
1517
  """
1550
1518
  # Store the code in a set to avoid duplicates.
1551
- code = set()
1519
+ code: dict[str, None] = {}
1552
1520
 
1553
1521
  # Add the custom code for this component.
1554
1522
  custom_code = self._get_custom_code()
1555
1523
  if custom_code is not None:
1556
- code.add(custom_code)
1524
+ code[custom_code] = None
1557
1525
 
1558
1526
  for component in self._get_components_in_props():
1559
1527
  code |= component._get_all_custom_code()
@@ -1561,7 +1529,7 @@ class Component(BaseComponent, ABC):
1561
1529
  # Add the custom code from add_custom_code method.
1562
1530
  for clz in self._iter_parent_classes_with_method("add_custom_code"):
1563
1531
  for item in clz.add_custom_code(self):
1564
- code.add(item)
1532
+ code[item] = None
1565
1533
 
1566
1534
  # Add the custom code for the children.
1567
1535
  for child in self.children:
@@ -1846,7 +1814,7 @@ class Component(BaseComponent, ABC):
1846
1814
 
1847
1815
  # Add the hook code for the children.
1848
1816
  for child in self.children:
1849
- code = {**code, **child._get_all_hooks_internal()}
1817
+ code.update(child._get_all_hooks_internal())
1850
1818
 
1851
1819
  return code
1852
1820
 
@@ -1870,7 +1838,7 @@ class Component(BaseComponent, ABC):
1870
1838
 
1871
1839
  # Add the hook code for the children.
1872
1840
  for child in self.children:
1873
- code = {**code, **child._get_all_hooks()}
1841
+ code.update(child._get_all_hooks())
1874
1842
 
1875
1843
  return code
1876
1844
 
@@ -1885,16 +1853,16 @@ class Component(BaseComponent, ABC):
1885
1853
  return None
1886
1854
  return format.format_ref(self.id)
1887
1855
 
1888
- def _get_all_refs(self) -> set[str]:
1856
+ def _get_all_refs(self) -> dict[str, None]:
1889
1857
  """Get the refs for the children of the component.
1890
1858
 
1891
1859
  Returns:
1892
1860
  The refs for the children.
1893
1861
  """
1894
- refs = set()
1862
+ refs = {}
1895
1863
  ref = self.get_ref()
1896
1864
  if ref is not None:
1897
- refs.add(ref)
1865
+ refs[ref] = None
1898
1866
  for child in self.children:
1899
1867
  refs |= child._get_all_refs()
1900
1868
  for component in self._get_components_in_props():
@@ -2026,7 +1994,7 @@ class CustomComponent(Component):
2026
1994
  )
2027
1995
 
2028
1996
  to_camel_cased_props = {
2029
- format.to_camel_case(key + MEMO_MARKER)
1997
+ format.to_camel_case(key + MEMO_MARKER): None
2030
1998
  for key in props
2031
1999
  if key not in event_types
2032
2000
  }
@@ -2060,15 +2028,6 @@ class CustomComponent(Component):
2060
2028
  self.props[camel_cased_key] = value
2061
2029
  setattr(self, camel_cased_key, value)
2062
2030
 
2063
- @classmethod
2064
- def _are_fields_known(cls) -> bool:
2065
- """Check if the fields are known.
2066
-
2067
- Returns:
2068
- Whether the fields are known.
2069
- """
2070
- return False
2071
-
2072
2031
  def __eq__(self, other: Any) -> bool:
2073
2032
  """Check if the component is equal to another.
2074
2033
 
@@ -2089,13 +2048,13 @@ class CustomComponent(Component):
2089
2048
  return hash(self.tag)
2090
2049
 
2091
2050
  @classmethod
2092
- def get_props(cls) -> set[str]:
2051
+ def get_props(cls) -> Iterable[str]:
2093
2052
  """Get the props for the component.
2094
2053
 
2095
2054
  Returns:
2096
2055
  The set of component props.
2097
2056
  """
2098
- return set()
2057
+ return ()
2099
2058
 
2100
2059
  @staticmethod
2101
2060
  def _get_event_spec_from_args_spec(name: str, event: EventChain) -> Callable:
@@ -2697,7 +2656,7 @@ class StatefulComponent(BaseComponent):
2697
2656
  return set()
2698
2657
  return self.component._get_all_dynamic_imports()
2699
2658
 
2700
- def _get_all_custom_code(self, export: bool = False) -> set[str]:
2659
+ def _get_all_custom_code(self, export: bool = False) -> dict[str, None]:
2701
2660
  """Get custom code for the component.
2702
2661
 
2703
2662
  Args:
@@ -2707,19 +2666,19 @@ class StatefulComponent(BaseComponent):
2707
2666
  The custom code.
2708
2667
  """
2709
2668
  if self.rendered_as_shared:
2710
- return set()
2711
- return self.component._get_all_custom_code().union(
2712
- {self._render_stateful_code(export=export)}
2669
+ return {}
2670
+ return self.component._get_all_custom_code() | (
2671
+ {self._render_stateful_code(export=export): None}
2713
2672
  )
2714
2673
 
2715
- def _get_all_refs(self) -> set[str]:
2674
+ def _get_all_refs(self) -> dict[str, None]:
2716
2675
  """Get the refs for the children of the component.
2717
2676
 
2718
2677
  Returns:
2719
2678
  The refs for the children.
2720
2679
  """
2721
2680
  if self.rendered_as_shared:
2722
- return set()
2681
+ return {}
2723
2682
  return self.component._get_all_refs()
2724
2683
 
2725
2684
  def render(self) -> dict:
@@ -132,7 +132,7 @@ class DebounceInput(Component):
132
132
  component.children = child.children
133
133
  component._rename_props = child._rename_props # pyright: ignore[reportAttributeAccessIssue]
134
134
  outer_get_all_custom_code = component._get_all_custom_code
135
- component._get_all_custom_code = lambda: outer_get_all_custom_code().union(
135
+ component._get_all_custom_code = lambda: outer_get_all_custom_code() | (
136
136
  child._get_all_custom_code()
137
137
  )
138
138
  return component
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import functools
6
6
  import inspect
7
7
  from collections.abc import Callable, Iterable
8
+ from hashlib import md5
8
9
  from typing import Any
9
10
 
10
11
  from reflex.components.base.fragment import Fragment
@@ -141,25 +142,12 @@ class Foreach(Component):
141
142
  else:
142
143
  render_fn = self.render_fn
143
144
  # Otherwise, use a deterministic index, based on the render function bytecode.
144
- code_hash = (
145
- hash(
146
- getattr(
147
- render_fn,
148
- "__code__",
149
- (
150
- repr(self.render_fn)
151
- if not isinstance(render_fn, functools.partial)
152
- else render_fn.func.__code__
153
- ),
154
- )
155
- )
156
- .to_bytes(
157
- length=8,
158
- byteorder="big",
159
- signed=True,
160
- )
161
- .hex()
162
- )
145
+ if (render_fn_code := getattr(render_fn, "__code__", None)) is not None:
146
+ code_hash = md5(render_fn_code.co_code).hexdigest()
147
+ elif isinstance(render_fn, functools.partial):
148
+ code_hash = md5(render_fn.func.__code__.co_code).hexdigest()
149
+ else:
150
+ code_hash = md5(repr(render_fn).encode()).hexdigest()
163
151
  props["index_var_name"] = f"index_{code_hash}"
164
152
 
165
153
  return IterTag(
@@ -22,6 +22,9 @@ class StickyLogo(Svg):
22
22
  width: Var[int | str] | int | str | None = None,
23
23
  height: Var[int | str] | int | str | None = None,
24
24
  xmlns: Var[str] | str | None = None,
25
+ view_box: Var[str] | str | None = None,
26
+ preserve_aspect_ratio: Var[str] | str | None = None,
27
+ transform: Var[str] | str | None = None,
25
28
  access_key: Var[str] | str | None = None,
26
29
  auto_capitalize: Literal[
27
30
  "characters", "none", "off", "on", "sentences", "words"
@@ -260,7 +260,7 @@ class Upload(MemoizationLeaf):
260
260
  props["class_name"] = ["rx-Upload", *given_class_name]
261
261
 
262
262
  # get only upload component props
263
- supported_props = cls.get_props().union({"on_drop"})
263
+ supported_props = set(cls.get_props()) | {"on_drop"}
264
264
  upload_props = {
265
265
  key: value for key, value in props.items() if key in supported_props
266
266
  }
@@ -81,9 +81,7 @@ def load_dynamic_serializer():
81
81
  rendered_components.update(dict.fromkeys(dynamic_imports))
82
82
 
83
83
  # Include custom code in the shared component.
84
- rendered_components.update(
85
- dict.fromkeys(component._get_all_custom_code()),
86
- )
84
+ rendered_components.update(component._get_all_custom_code())
87
85
 
88
86
  rendered_components[
89
87
  templates.stateful_component_template(
@@ -770,7 +770,7 @@ class Textarea(BaseHTML):
770
770
  "enter_key_submit",
771
771
  ]
772
772
 
773
- def _get_all_custom_code(self) -> set[str]:
773
+ def _get_all_custom_code(self) -> dict[str, None]:
774
774
  """Include the custom code for auto_height and enter_key_submit functionality.
775
775
 
776
776
  Returns:
@@ -778,9 +778,9 @@ class Textarea(BaseHTML):
778
778
  """
779
779
  custom_code = super()._get_all_custom_code()
780
780
  if self.auto_height is not None:
781
- custom_code.add(AUTO_HEIGHT_JS)
781
+ custom_code[AUTO_HEIGHT_JS] = None
782
782
  if self.enter_key_submit is not None:
783
- custom_code.add(ENTER_KEY_SUBMIT_JS)
783
+ custom_code[ENTER_KEY_SUBMIT_JS] = None
784
784
  return custom_code
785
785
 
786
786