reflex 0.7.13a2__py3-none-any.whl → 0.7.14a2__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.

Files changed (256) hide show
  1. reflex/.templates/apps/blank/code/blank.py +0 -2
  2. reflex/app.py +64 -69
  3. reflex/app_mixins/lifespan.py +2 -3
  4. reflex/app_mixins/middleware.py +1 -0
  5. reflex/app_mixins/mixin.py +0 -1
  6. reflex/assets.py +6 -3
  7. reflex/base.py +3 -2
  8. reflex/compiler/compiler.py +77 -64
  9. reflex/compiler/utils.py +8 -6
  10. reflex/components/base/app_wrap.pyi +0 -1
  11. reflex/components/base/bare.py +5 -7
  12. reflex/components/base/body.pyi +0 -1
  13. reflex/components/base/document.pyi +0 -5
  14. reflex/components/base/error_boundary.pyi +0 -1
  15. reflex/components/base/fragment.pyi +0 -1
  16. reflex/components/base/head.pyi +0 -2
  17. reflex/components/base/link.pyi +0 -2
  18. reflex/components/base/meta.py +2 -1
  19. reflex/components/base/meta.pyi +0 -4
  20. reflex/components/base/script.py +2 -1
  21. reflex/components/base/script.pyi +0 -1
  22. reflex/components/base/strict_mode.pyi +0 -1
  23. reflex/components/component.py +49 -41
  24. reflex/components/core/auto_scroll.pyi +0 -1
  25. reflex/components/core/banner.pyi +0 -6
  26. reflex/components/core/breakpoints.py +9 -11
  27. reflex/components/core/client_side_routing.pyi +0 -2
  28. reflex/components/core/clipboard.pyi +0 -1
  29. reflex/components/core/colors.py +10 -7
  30. reflex/components/core/cond.py +4 -2
  31. reflex/components/core/debounce.py +5 -3
  32. reflex/components/core/debounce.pyi +0 -1
  33. reflex/components/core/foreach.py +8 -6
  34. reflex/components/core/html.py +3 -3
  35. reflex/components/core/html.pyi +0 -1
  36. reflex/components/core/match.py +19 -17
  37. reflex/components/core/sticky.pyi +0 -4
  38. reflex/components/core/upload.pyi +0 -5
  39. reflex/components/datadisplay/code.py +1 -2
  40. reflex/components/datadisplay/code.pyi +0 -2
  41. reflex/components/datadisplay/dataeditor.py +7 -10
  42. reflex/components/datadisplay/dataeditor.pyi +0 -1
  43. reflex/components/datadisplay/logo.py +3 -4
  44. reflex/components/datadisplay/shiki_code_block.py +8 -11
  45. reflex/components/datadisplay/shiki_code_block.pyi +0 -3
  46. reflex/components/dynamic.py +2 -3
  47. reflex/components/el/__init__.pyi +2 -0
  48. reflex/components/el/element.pyi +0 -1
  49. reflex/components/el/elements/__init__.py +1 -0
  50. reflex/components/el/elements/__init__.pyi +3 -0
  51. reflex/components/el/elements/base.pyi +0 -1
  52. reflex/components/el/elements/forms.py +14 -15
  53. reflex/components/el/elements/forms.pyi +15 -32
  54. reflex/components/el/elements/inline.pyi +0 -28
  55. reflex/components/el/elements/media.py +26 -0
  56. reflex/components/el/elements/media.pyi +259 -25
  57. reflex/components/el/elements/metadata.py +0 -1
  58. reflex/components/el/elements/metadata.pyi +0 -6
  59. reflex/components/el/elements/other.pyi +0 -7
  60. reflex/components/el/elements/scripts.pyi +0 -3
  61. reflex/components/el/elements/sectioning.pyi +0 -15
  62. reflex/components/el/elements/tables.pyi +0 -10
  63. reflex/components/el/elements/typography.pyi +0 -15
  64. reflex/components/gridjs/datatable.py +10 -13
  65. reflex/components/gridjs/datatable.pyi +0 -2
  66. reflex/components/lucide/icon.py +10 -9
  67. reflex/components/lucide/icon.pyi +0 -3
  68. reflex/components/markdown/markdown.py +6 -8
  69. reflex/components/markdown/markdown.pyi +0 -1
  70. reflex/components/moment/moment.pyi +0 -1
  71. reflex/components/next/base.py +0 -2
  72. reflex/components/next/base.pyi +0 -3
  73. reflex/components/next/image.pyi +0 -1
  74. reflex/components/next/link.pyi +0 -1
  75. reflex/components/next/video.pyi +0 -1
  76. reflex/components/plotly/plotly.pyi +0 -9
  77. reflex/components/props.py +4 -3
  78. reflex/components/radix/primitives/accordion.pyi +0 -7
  79. reflex/components/radix/primitives/base.py +1 -3
  80. reflex/components/radix/primitives/base.pyi +0 -2
  81. reflex/components/radix/primitives/drawer.pyi +0 -11
  82. reflex/components/radix/primitives/form.py +4 -8
  83. reflex/components/radix/primitives/form.pyi +0 -12
  84. reflex/components/radix/primitives/progress.py +1 -1
  85. reflex/components/radix/primitives/progress.pyi +0 -5
  86. reflex/components/radix/primitives/slider.py +1 -1
  87. reflex/components/radix/primitives/slider.pyi +0 -5
  88. reflex/components/radix/themes/base.pyi +0 -8
  89. reflex/components/radix/themes/color_mode.pyi +0 -3
  90. reflex/components/radix/themes/components/alert_dialog.py +4 -2
  91. reflex/components/radix/themes/components/alert_dialog.pyi +4 -9
  92. reflex/components/radix/themes/components/aspect_ratio.py +1 -2
  93. reflex/components/radix/themes/components/aspect_ratio.pyi +1 -3
  94. reflex/components/radix/themes/components/avatar.py +5 -2
  95. reflex/components/radix/themes/components/avatar.pyi +1 -3
  96. reflex/components/radix/themes/components/badge.py +5 -2
  97. reflex/components/radix/themes/components/badge.pyi +1 -3
  98. reflex/components/radix/themes/components/button.py +2 -3
  99. reflex/components/radix/themes/components/button.pyi +1 -3
  100. reflex/components/radix/themes/components/callout.py +1 -2
  101. reflex/components/radix/themes/components/callout.pyi +1 -7
  102. reflex/components/radix/themes/components/card.py +1 -2
  103. reflex/components/radix/themes/components/card.pyi +1 -3
  104. reflex/components/radix/themes/components/checkbox.py +7 -4
  105. reflex/components/radix/themes/components/checkbox.pyi +1 -5
  106. reflex/components/radix/themes/components/checkbox_cards.py +1 -2
  107. reflex/components/radix/themes/components/checkbox_cards.pyi +1 -4
  108. reflex/components/radix/themes/components/checkbox_group.py +1 -2
  109. reflex/components/radix/themes/components/checkbox_group.pyi +1 -4
  110. reflex/components/radix/themes/components/context_menu.py +1 -1
  111. reflex/components/radix/themes/components/context_menu.pyi +1 -14
  112. reflex/components/radix/themes/components/data_list.py +1 -2
  113. reflex/components/radix/themes/components/data_list.pyi +1 -6
  114. reflex/components/radix/themes/components/dialog.py +4 -2
  115. reflex/components/radix/themes/components/dialog.pyi +4 -9
  116. reflex/components/radix/themes/components/dropdown_menu.py +5 -2
  117. reflex/components/radix/themes/components/dropdown_menu.pyi +4 -10
  118. reflex/components/radix/themes/components/hover_card.py +4 -2
  119. reflex/components/radix/themes/components/hover_card.pyi +4 -6
  120. reflex/components/radix/themes/components/icon_button.py +7 -8
  121. reflex/components/radix/themes/components/icon_button.pyi +1 -3
  122. reflex/components/radix/themes/components/inset.py +1 -2
  123. reflex/components/radix/themes/components/inset.pyi +1 -3
  124. reflex/components/radix/themes/components/popover.py +4 -2
  125. reflex/components/radix/themes/components/popover.pyi +4 -6
  126. reflex/components/radix/themes/components/progress.py +1 -2
  127. reflex/components/radix/themes/components/progress.pyi +1 -3
  128. reflex/components/radix/themes/components/radio.py +1 -2
  129. reflex/components/radix/themes/components/radio.pyi +1 -3
  130. reflex/components/radix/themes/components/radio_cards.py +1 -2
  131. reflex/components/radix/themes/components/radio_cards.pyi +1 -4
  132. reflex/components/radix/themes/components/radio_group.py +7 -5
  133. reflex/components/radix/themes/components/radio_group.pyi +1 -6
  134. reflex/components/radix/themes/components/scroll_area.py +1 -2
  135. reflex/components/radix/themes/components/scroll_area.pyi +1 -3
  136. reflex/components/radix/themes/components/segmented_control.py +1 -2
  137. reflex/components/radix/themes/components/segmented_control.pyi +1 -4
  138. reflex/components/radix/themes/components/select.py +5 -2
  139. reflex/components/radix/themes/components/select.pyi +1 -11
  140. reflex/components/radix/themes/components/separator.py +1 -2
  141. reflex/components/radix/themes/components/separator.pyi +1 -3
  142. reflex/components/radix/themes/components/skeleton.py +1 -2
  143. reflex/components/radix/themes/components/skeleton.pyi +1 -3
  144. reflex/components/radix/themes/components/slider.py +1 -2
  145. reflex/components/radix/themes/components/slider.pyi +1 -3
  146. reflex/components/radix/themes/components/spinner.py +1 -2
  147. reflex/components/radix/themes/components/spinner.pyi +1 -3
  148. reflex/components/radix/themes/components/switch.py +1 -2
  149. reflex/components/radix/themes/components/switch.pyi +1 -3
  150. reflex/components/radix/themes/components/table.py +1 -2
  151. reflex/components/radix/themes/components/table.pyi +1 -9
  152. reflex/components/radix/themes/components/tabs.py +1 -2
  153. reflex/components/radix/themes/components/tabs.pyi +1 -7
  154. reflex/components/radix/themes/components/text_area.py +5 -2
  155. reflex/components/radix/themes/components/text_area.pyi +2 -4
  156. reflex/components/radix/themes/components/text_field.py +5 -2
  157. reflex/components/radix/themes/components/text_field.pyi +1 -5
  158. reflex/components/radix/themes/components/tooltip.py +1 -2
  159. reflex/components/radix/themes/components/tooltip.pyi +1 -3
  160. reflex/components/radix/themes/layout/base.py +5 -2
  161. reflex/components/radix/themes/layout/base.pyi +5 -3
  162. reflex/components/radix/themes/layout/box.py +1 -2
  163. reflex/components/radix/themes/layout/box.pyi +1 -3
  164. reflex/components/radix/themes/layout/center.pyi +0 -1
  165. reflex/components/radix/themes/layout/container.py +1 -2
  166. reflex/components/radix/themes/layout/container.pyi +1 -3
  167. reflex/components/radix/themes/layout/flex.py +6 -2
  168. reflex/components/radix/themes/layout/flex.pyi +1 -3
  169. reflex/components/radix/themes/layout/grid.py +6 -2
  170. reflex/components/radix/themes/layout/grid.pyi +1 -3
  171. reflex/components/radix/themes/layout/list.py +2 -1
  172. reflex/components/radix/themes/layout/list.pyi +0 -5
  173. reflex/components/radix/themes/layout/section.py +1 -2
  174. reflex/components/radix/themes/layout/section.pyi +1 -3
  175. reflex/components/radix/themes/layout/spacer.pyi +0 -1
  176. reflex/components/radix/themes/layout/stack.py +1 -1
  177. reflex/components/radix/themes/layout/stack.pyi +0 -3
  178. reflex/components/radix/themes/typography/blockquote.py +1 -1
  179. reflex/components/radix/themes/typography/blockquote.pyi +1 -3
  180. reflex/components/radix/themes/typography/code.py +5 -1
  181. reflex/components/radix/themes/typography/code.pyi +1 -3
  182. reflex/components/radix/themes/typography/heading.py +1 -1
  183. reflex/components/radix/themes/typography/heading.pyi +1 -3
  184. reflex/components/radix/themes/typography/link.py +3 -2
  185. reflex/components/radix/themes/typography/link.pyi +1 -3
  186. reflex/components/radix/themes/typography/text.py +1 -1
  187. reflex/components/radix/themes/typography/text.pyi +1 -9
  188. reflex/components/react_player/audio.py +0 -2
  189. reflex/components/react_player/audio.pyi +0 -3
  190. reflex/components/react_player/react_player.pyi +0 -1
  191. reflex/components/react_player/video.py +0 -2
  192. reflex/components/react_player/video.pyi +0 -3
  193. reflex/components/recharts/__init__.py +1 -1
  194. reflex/components/recharts/__init__.pyi +1 -1
  195. reflex/components/recharts/cartesian.py +20 -25
  196. reflex/components/recharts/cartesian.pyi +20 -37
  197. reflex/components/recharts/charts.py +2 -1
  198. reflex/components/recharts/charts.pyi +0 -12
  199. reflex/components/recharts/general.pyi +0 -6
  200. reflex/components/recharts/polar.py +5 -4
  201. reflex/components/recharts/polar.pyi +4 -10
  202. reflex/components/recharts/recharts.py +12 -10
  203. reflex/components/recharts/recharts.pyi +10 -11
  204. reflex/components/sonner/toast.py +2 -2
  205. reflex/components/sonner/toast.pyi +0 -2
  206. reflex/components/suneditor/editor.py +2 -1
  207. reflex/components/suneditor/editor.pyi +0 -1
  208. reflex/components/tags/iter_tag.py +4 -2
  209. reflex/config.py +47 -35
  210. reflex/constants/base.py +3 -3
  211. reflex/constants/compiler.py +8 -6
  212. reflex/constants/installer.py +24 -15
  213. reflex/custom_components/custom_components.py +1 -2
  214. reflex/event.py +58 -60
  215. reflex/experimental/__init__.py +2 -2
  216. reflex/experimental/client_state.py +9 -4
  217. reflex/experimental/layout.pyi +0 -5
  218. reflex/istate/manager.py +15 -19
  219. reflex/istate/proxy.py +19 -12
  220. reflex/model.py +6 -4
  221. reflex/plugins/base.py +8 -0
  222. reflex/plugins/tailwind_v3.py +8 -0
  223. reflex/plugins/tailwind_v4.py +8 -0
  224. reflex/reflex.py +9 -11
  225. reflex/route.py +7 -9
  226. reflex/state.py +66 -70
  227. reflex/style.py +3 -1
  228. reflex/testing.py +46 -29
  229. reflex/utils/build.py +2 -1
  230. reflex/utils/console.py +9 -17
  231. reflex/utils/exec.py +9 -11
  232. reflex/utils/format.py +21 -24
  233. reflex/utils/imports.py +4 -3
  234. reflex/utils/lazy_loader.py +3 -3
  235. reflex/utils/misc.py +2 -1
  236. reflex/utils/net.py +2 -2
  237. reflex/utils/path_ops.py +2 -1
  238. reflex/utils/prerequisites.py +67 -38
  239. reflex/utils/processes.py +4 -6
  240. reflex/utils/pyi_generator.py +46 -41
  241. reflex/utils/redir.py +1 -1
  242. reflex/utils/serializers.py +4 -4
  243. reflex/utils/telemetry.py +20 -2
  244. reflex/utils/types.py +16 -13
  245. reflex/vars/base.py +96 -109
  246. reflex/vars/datetime.py +2 -1
  247. reflex/vars/dep_tracking.py +19 -28
  248. reflex/vars/number.py +6 -7
  249. reflex/vars/object.py +5 -6
  250. reflex/vars/sequence.py +11 -11
  251. {reflex-0.7.13a2.dist-info → reflex-0.7.14a2.dist-info}/METADATA +1 -1
  252. reflex-0.7.14a2.dist-info/RECORD +407 -0
  253. reflex-0.7.13a2.dist-info/RECORD +0 -407
  254. {reflex-0.7.13a2.dist-info → reflex-0.7.14a2.dist-info}/WHEEL +0 -0
  255. {reflex-0.7.13a2.dist-info → reflex-0.7.14a2.dist-info}/entry_points.txt +0 -0
  256. {reflex-0.7.13a2.dist-info → reflex-0.7.14a2.dist-info}/licenses/LICENSE +0 -0
reflex/state.py CHANGED
@@ -148,7 +148,8 @@ def _no_chain_background_task(
148
148
 
149
149
  return _no_chain_background_task_gen
150
150
 
151
- raise TypeError(f"{fn} is marked as a background task, but is not async.")
151
+ msg = f"{fn} is marked as a background task, but is not async."
152
+ raise TypeError(msg)
152
153
 
153
154
 
154
155
  def _substate_key(
@@ -233,22 +234,19 @@ class EventHandlerSetVar(EventHandler):
233
234
 
234
235
  if args:
235
236
  if not isinstance(args[0], str):
236
- raise EventHandlerValueError(
237
- f"Var name must be passed as a string, got {args[0]!r}"
238
- )
237
+ msg = f"Var name must be passed as a string, got {args[0]!r}"
238
+ raise EventHandlerValueError(msg)
239
239
 
240
240
  handler = getattr(self.state_cls, constants.SETTER_PREFIX + args[0], None)
241
241
 
242
242
  # Check that the requested Var setter exists on the State at compile time.
243
243
  if handler is None:
244
- raise AttributeError(
245
- f"Variable `{args[0]}` cannot be set on `{self.state_cls.get_full_name()}`"
246
- )
244
+ msg = f"Variable `{args[0]}` cannot be set on `{self.state_cls.get_full_name()}`"
245
+ raise AttributeError(msg)
247
246
 
248
247
  if asyncio.iscoroutinefunction(handler.fn):
249
- raise NotImplementedError(
250
- f"Setter for {args[0]} is async, which is not supported."
251
- )
248
+ msg = f"Setter for {args[0]} is async, which is not supported."
249
+ raise NotImplementedError(msg)
252
250
 
253
251
  return super().__call__(*args)
254
252
 
@@ -406,14 +404,14 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
406
404
  from reflex.utils.exceptions import ReflexRuntimeError
407
405
 
408
406
  if not _reflex_internal_init and not is_testing_env():
409
- raise ReflexRuntimeError(
407
+ msg = (
410
408
  "State classes should not be instantiated directly in a Reflex app. "
411
409
  "See https://reflex.dev/docs/state/ for further information."
412
410
  )
411
+ raise ReflexRuntimeError(msg)
413
412
  if type(self)._mixin:
414
- raise ReflexRuntimeError(
415
- f"{type(self).__name__} is a state mixin and cannot be instantiated directly."
416
- )
413
+ msg = f"{type(self).__name__} is a state mixin and cannot be instantiated directly."
414
+ raise ReflexRuntimeError(msg)
417
415
  kwargs["parent_state"] = parent_state
418
416
  super().__init__()
419
417
  for name, value in kwargs.items():
@@ -462,10 +460,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
462
460
  NameError: If the module name is invalid.
463
461
  """
464
462
  if "___" in cls.__module__:
465
- raise NameError(
463
+ msg = (
466
464
  "The module name of a State class cannot contain '___'. "
467
465
  "Please rename the module."
468
466
  )
467
+ raise NameError(msg)
469
468
 
470
469
  @classmethod
471
470
  def __init_subclass__(cls, mixin: bool = False, **kwargs):
@@ -515,10 +514,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
515
514
  # Check if another substate class with the same name has already been defined.
516
515
  if cls.get_name() in {c.get_name() for c in parent_state.class_subclasses}:
517
516
  # This should not happen, since we have added module prefix to state names in #3214
518
- raise StateValueError(
517
+ msg = (
519
518
  f"The substate class '{cls.get_name()}' has been defined multiple times. "
520
519
  "Shadowing substate classes is not allowed."
521
520
  )
521
+ raise StateValueError(msg)
522
522
  # Track this new subclass in the parent state's subclasses set.
523
523
  parent_state.class_subclasses.add(cls)
524
524
 
@@ -832,9 +832,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
832
832
  overridden_methods.add(method.__name__)
833
833
 
834
834
  for method_name in overridden_methods:
835
- raise EventHandlerShadowsBuiltInStateMethodError(
836
- f"The event handler name `{method_name}` shadows a builtin State method; use a different name instead"
837
- )
835
+ msg = f"The event handler name `{method_name}` shadows a builtin State method; use a different name instead"
836
+ raise EventHandlerShadowsBuiltInStateMethodError(msg)
838
837
 
839
838
  @classmethod
840
839
  def _check_overridden_basevars(cls):
@@ -845,9 +844,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
845
844
  """
846
845
  for computed_var_ in cls._get_computed_vars():
847
846
  if computed_var_._js_expr in cls.__annotations__:
848
- raise ComputedVarShadowsBaseVarsError(
849
- f"The computed var name `{computed_var_._js_expr}` shadows a base var in {cls.__module__}.{cls.__name__}; use a different name instead"
850
- )
847
+ msg = f"The computed var name `{computed_var_._js_expr}` shadows a base var in {cls.__module__}.{cls.__name__}; use a different name instead"
848
+ raise ComputedVarShadowsBaseVarsError(msg)
851
849
 
852
850
  @classmethod
853
851
  def _check_overridden_computed_vars(cls) -> None:
@@ -861,9 +859,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
861
859
  continue
862
860
  name = cv._js_expr
863
861
  if name in cls.inherited_vars or name in cls.inherited_backend_vars:
864
- raise ComputedVarShadowsStateVarError(
865
- f"The computed var name `{cv._js_expr}` shadows a var in {cls.__module__}.{cls.__name__}; use a different name instead"
866
- )
862
+ msg = f"The computed var name `{cv._js_expr}` shadows a var in {cls.__module__}.{cls.__name__}; use a different name instead"
863
+ raise ComputedVarShadowsStateVarError(msg)
867
864
 
868
865
  @classmethod
869
866
  def get_skip_vars(cls) -> set[str]:
@@ -901,7 +898,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
901
898
  if issubclass(base, BaseState) and base is not BaseState and not base._mixin
902
899
  ]
903
900
  if len(parent_states) >= 2:
904
- raise ValueError(f"Only one parent state is allowed {parent_states}.")
901
+ msg = f"Only one parent state is allowed {parent_states}."
902
+ raise ValueError(msg)
905
903
  # The first non-mixin state in the mro is our parent.
906
904
  for base in cls.mro()[1:]:
907
905
  if not issubclass(base, BaseState) or base._mixin:
@@ -953,7 +951,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
953
951
  name = cls.get_name()
954
952
  parent_state = cls.get_parent_state()
955
953
  if parent_state is not None:
956
- name = ".".join((parent_state.get_full_name(), name))
954
+ name = parent_state.get_full_name() + "." + name
957
955
  return name
958
956
 
959
957
  @classmethod
@@ -982,7 +980,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
982
980
  for substate in cls.get_substates():
983
981
  if path[0] == substate.get_name():
984
982
  return substate.get_class_substate(path[1:])
985
- raise ValueError(f"Invalid path: {path}")
983
+ msg = f"Invalid path: {path}"
984
+ raise ValueError(msg)
986
985
 
987
986
  @classmethod
988
987
  def get_class_var(cls, path: Sequence[str]) -> Any:
@@ -1000,7 +999,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1000
999
  path, name = path[:-1], path[-1]
1001
1000
  substate = cls.get_class_substate(tuple(path))
1002
1001
  if not hasattr(substate, name):
1003
- raise ValueError(f"Invalid path: {path}")
1002
+ msg = f"Invalid path: {path}"
1003
+ raise ValueError(msg)
1004
1004
  return getattr(substate, name)
1005
1005
 
1006
1006
  @classmethod
@@ -1029,12 +1029,13 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1029
1029
  from reflex.utils.exceptions import VarTypeError
1030
1030
 
1031
1031
  if not types.is_valid_var_type(prop._var_type):
1032
- raise VarTypeError(
1032
+ msg = (
1033
1033
  "State vars must be of a serializable type. "
1034
1034
  "Valid types include strings, numbers, booleans, lists, "
1035
1035
  "dictionaries, dataclasses, datetime objects, and pydantic models. "
1036
1036
  f'Found var "{prop._js_expr}" with type {prop._var_type}.'
1037
1037
  )
1038
+ raise VarTypeError(msg)
1038
1039
  cls._set_var(prop)
1039
1040
  if cls.is_user_defined() and get_config().state_auto_setters:
1040
1041
  cls._create_setter(prop)
@@ -1056,9 +1057,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1056
1057
  NameError: if a variable of this name already exists
1057
1058
  """
1058
1059
  if name in cls.__fields__:
1059
- raise NameError(
1060
- f"The variable '{name}' already exist. Use a different name"
1061
- )
1060
+ msg = f"The variable '{name}' already exist. Use a different name"
1061
+ raise NameError(msg)
1062
1062
 
1063
1063
  # create the variable based on name and type
1064
1064
  var = Var(
@@ -1260,9 +1260,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1260
1260
  arg in cls.computed_vars
1261
1261
  and not isinstance(cls.computed_vars[arg], DynamicRouteVar)
1262
1262
  ) or arg in cls.base_vars:
1263
- raise DynamicRouteArgShadowsStateVarError(
1264
- f"Dynamic route arg '{arg}' is shadowing an existing var in {cls.__module__}.{cls.__name__}"
1265
- )
1263
+ msg = f"Dynamic route arg '{arg}' is shadowing an existing var in {cls.__module__}.{cls.__name__}"
1264
+ raise DynamicRouteArgShadowsStateVarError(msg)
1266
1265
  for substate in cls.get_substates():
1267
1266
  substate._check_overwritten_dynamic_args(args)
1268
1267
 
@@ -1363,10 +1362,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1363
1362
  f"_{getattr(type(self), '__original_name__', type(self).__name__)}__"
1364
1363
  )
1365
1364
  ):
1366
- raise SetUndefinedStateVarError(
1365
+ msg = (
1367
1366
  f"The state variable '{name}' has not been defined in '{type(self).__name__}'. "
1368
1367
  f"All state variables must be declared before they can be set."
1369
1368
  )
1369
+ raise SetUndefinedStateVarError(msg)
1370
1370
 
1371
1371
  fields = self.get_fields()
1372
1372
 
@@ -1470,7 +1470,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1470
1470
  return self
1471
1471
  path = path[1:]
1472
1472
  if path[0] not in self.substates:
1473
- raise ValueError(f"Invalid path: {path}")
1473
+ msg = f"Invalid path: {path}"
1474
+ raise ValueError(msg)
1474
1475
  return self.substates[path[0]].get_substate(path[1:])
1475
1476
 
1476
1477
  @classmethod
@@ -1517,10 +1518,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1517
1518
  # Then get the target state and all its substates.
1518
1519
  state_manager = get_state_manager()
1519
1520
  if not isinstance(state_manager, StateManagerRedis):
1520
- raise RuntimeError(
1521
+ msg = (
1521
1522
  f"Requested state {state_cls.get_full_name()} is not cached and cannot be accessed without redis. "
1522
- "(All states should already be available -- this is likely a bug).",
1523
+ "(All states should already be available -- this is likely a bug)."
1523
1524
  )
1525
+ raise RuntimeError(msg)
1524
1526
  state_in_redis = await state_manager.get_state(
1525
1527
  token=_substate_key(self.router.session.client_token, state_cls),
1526
1528
  top_level=False,
@@ -1528,9 +1530,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1528
1530
  )
1529
1531
 
1530
1532
  if not isinstance(state_in_redis, state_cls):
1531
- raise StateMismatchError(
1532
- f"Searched for state {state_cls.get_full_name()} but found {state_in_redis}."
1533
- )
1533
+ msg = f"Searched for state {state_cls.get_full_name()} but found {state_in_redis}."
1534
+ raise StateMismatchError(msg)
1534
1535
 
1535
1536
  return state_in_redis
1536
1537
 
@@ -1549,9 +1550,10 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1549
1550
  root_state = self._get_root_state()
1550
1551
  substate = root_state.get_substate(state_cls.get_full_name().split("."))
1551
1552
  if not isinstance(substate, state_cls):
1552
- raise StateMismatchError(
1553
+ msg = (
1553
1554
  f"Searched for state {state_cls.get_full_name()} but found {substate}."
1554
1555
  )
1556
+ raise StateMismatchError(msg)
1555
1557
  return substate
1556
1558
 
1557
1559
  async def get_state(self, state_cls: type[T_STATE]) -> T_STATE:
@@ -1601,9 +1603,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1601
1603
 
1602
1604
  var_data = var._get_all_var_data()
1603
1605
  if var_data is None or not var_data.state:
1604
- raise UnretrievableVarValueError(
1605
- f"Unable to retrieve value for {var._js_expr}: not associated with any state."
1606
- )
1606
+ msg = f"Unable to retrieve value for {var._js_expr}: not associated with any state."
1607
+ raise UnretrievableVarValueError(msg)
1607
1608
  # Fastish case: this var belongs to this state
1608
1609
  if var_data.state == self.get_full_name():
1609
1610
  return getattr(self, var_data.field_name)
@@ -1634,9 +1635,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1634
1635
  path, name = path[:-1], path[-1]
1635
1636
  substate = self.get_substate(path)
1636
1637
  if not substate:
1637
- raise ValueError(
1638
- "The value of state cannot be None when processing an event."
1639
- )
1638
+ msg = "The value of state cannot be None when processing an event."
1639
+ raise ValueError(msg)
1640
1640
  handler = substate.event_handlers[name]
1641
1641
 
1642
1642
  # For background tasks, proxy the state
@@ -1702,10 +1702,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1702
1702
  "ignore", message=f"coroutine '{coroutine_name}' was never awaited"
1703
1703
  )
1704
1704
 
1705
- raise TypeError(
1705
+ msg = (
1706
1706
  f"Your handler {handler.fn.__qualname__} must only return/yield: None, Events or other EventHandlers referenced by their class (i.e. using `type(self)` or other class references)."
1707
1707
  f" Returned events of types {', '.join(map(str, map(type, events)))!s}."
1708
1708
  )
1709
+ raise TypeError(msg)
1709
1710
 
1710
1711
  async def _as_state_update(
1711
1712
  self,
@@ -1834,9 +1835,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
1834
1835
  try:
1835
1836
  payload[arg] = hinted_args(value)
1836
1837
  except ValueError:
1837
- raise ValueError(
1838
- f"Received a string value ({value}) for {arg} but expected a {hinted_args}"
1839
- ) from None
1838
+ msg = f"Received a string value ({value}) for {arg} but expected a {hinted_args}"
1839
+ raise ValueError(msg) from None
1840
1840
  else:
1841
1841
  console.warn(
1842
1842
  f"Received a string value ({value}) for {arg} but expected a {hinted_args}. A simple conversion was successful."
@@ -2123,9 +2123,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
2123
2123
  Raises:
2124
2124
  TypeError: always, because async contextmanager protocol is only supported for background task.
2125
2125
  """
2126
- raise TypeError(
2127
- "Only background task should use `async with self` to modify state."
2128
- )
2126
+ msg = "Only background task should use `async with self` to modify state."
2127
+ raise TypeError(msg)
2129
2128
 
2130
2129
  async def __aexit__(self, *exc_info: Any) -> None:
2131
2130
  """Exit the async context manager protocol.
@@ -2136,7 +2135,6 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
2136
2135
  Args:
2137
2136
  exc_info: The exception info tuple.
2138
2137
  """
2139
- pass
2140
2138
 
2141
2139
  def __getstate__(self):
2142
2140
  """Get the state for redis serialization.
@@ -2298,9 +2296,10 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
2298
2296
  elif fp is not None and data is None:
2299
2297
  (substate_schema, state) = pickle.load(fp)
2300
2298
  else:
2301
- raise ValueError("Only one of `data` or `fp` must be provided")
2299
+ msg = "Only one of `data` or `fp` must be provided"
2300
+ raise ValueError(msg)
2302
2301
  if substate_schema != state._to_schema():
2303
- raise StateSchemaMismatchError()
2302
+ raise StateSchemaMismatchError
2304
2303
  return state
2305
2304
 
2306
2305
 
@@ -2377,14 +2376,12 @@ def dynamic(func: Callable[[T], Component]):
2377
2376
  values = list(func_signature.values())
2378
2377
 
2379
2378
  if number_of_parameters != 1:
2380
- raise DynamicComponentInvalidSignatureError(
2381
- "The function must have exactly one parameter, which is the state class."
2382
- )
2379
+ msg = "The function must have exactly one parameter, which is the state class."
2380
+ raise DynamicComponentInvalidSignatureError(msg)
2383
2381
 
2384
2382
  if len(values) != 1:
2385
- raise DynamicComponentInvalidSignatureError(
2386
- "You must provide a type hint for the state class in the function."
2387
- )
2383
+ msg = "You must provide a type hint for the state class in the function."
2384
+ raise DynamicComponentInvalidSignatureError(msg)
2388
2385
 
2389
2386
  state_class: type[T] = values[0]
2390
2387
 
@@ -2457,7 +2454,7 @@ class OnLoadInternalState(State):
2457
2454
  )
2458
2455
  if not load_events:
2459
2456
  self.is_hydrated = True
2460
- return # Fast path for navigation with no on_load events defined.
2457
+ return None # Fast path for navigation with no on_load events defined.
2461
2458
  self.is_hydrated = False
2462
2459
  return [
2463
2460
  *fix_events(
@@ -2549,9 +2546,8 @@ class ComponentState(State, mixin=True):
2549
2546
  Raises:
2550
2547
  NotImplementedError: if the subclass does not override this method.
2551
2548
  """
2552
- raise NotImplementedError(
2553
- f"{cls.__name__} must implement get_component to return the component instance."
2554
- )
2549
+ msg = f"{cls.__name__} must implement get_component to return the component instance."
2550
+ raise NotImplementedError(msg)
2555
2551
 
2556
2552
  @classmethod
2557
2553
  def create(cls, *children, **props) -> Component:
reflex/style.py CHANGED
@@ -121,10 +121,11 @@ def convert_item(
121
121
  ReflexError: If an EventHandler is used as a style value
122
122
  """
123
123
  if isinstance(style_item, EventHandler):
124
- raise ReflexError(
124
+ msg = (
125
125
  "EventHandlers cannot be used as style values. "
126
126
  "Please use a Var or a literal value."
127
127
  )
128
+ raise ReflexError(msg)
128
129
 
129
130
  if isinstance(style_item, Var):
130
131
  return style_item, style_item._get_all_var_data()
@@ -381,6 +382,7 @@ def format_as_emotion(style_dict: dict[str, Any]) -> Style | None:
381
382
  if _var_data is not None:
382
383
  emotion_style._var_data = VarData.merge(emotion_style._var_data, _var_data)
383
384
  return emotion_style
385
+ return None
384
386
 
385
387
 
386
388
  def convert_dict_to_style_and_format_emotion(
reflex/testing.py CHANGED
@@ -155,9 +155,8 @@ class AppHarness:
155
155
  app_name = f"{func_name}_{slug_suffix}"
156
156
  app_name = re.sub(r"[^a-zA-Z0-9_]", "_", app_name)
157
157
  elif isinstance(app_source, str):
158
- raise ValueError(
159
- "app_name must be provided when app_source is a string."
160
- )
158
+ msg = "app_name must be provided when app_source is a string."
159
+ raise ValueError(msg)
161
160
  else:
162
161
  app_name = app_source.__name__
163
162
 
@@ -285,7 +284,8 @@ class AppHarness:
285
284
  self.app_instance._state_manager, StateManagerRedis
286
285
  ):
287
286
  if self.app_instance._state is None:
288
- raise RuntimeError("State is not set.")
287
+ msg = "State is not set."
288
+ raise RuntimeError(msg)
289
289
  # Create our own redis connection for testing.
290
290
  self.state_manager = StateManagerRedis.create(self.app_instance._state)
291
291
  else:
@@ -299,7 +299,8 @@ class AppHarness:
299
299
 
300
300
  def _get_backend_shutdown_handler(self):
301
301
  if self.backend is None:
302
- raise RuntimeError("Backend was not initialized.")
302
+ msg = "Backend was not initialized."
303
+ raise RuntimeError(msg)
303
304
 
304
305
  original_shutdown = self.backend.shutdown
305
306
 
@@ -330,7 +331,8 @@ class AppHarness:
330
331
 
331
332
  def _start_backend(self, port: int = 0):
332
333
  if self.app_asgi is None:
333
- raise RuntimeError("App was not initialized.")
334
+ msg = "App was not initialized."
335
+ raise RuntimeError(msg)
334
336
  self.backend = uvicorn.Server(
335
337
  uvicorn.Config(
336
338
  app=self.app_asgi,
@@ -366,7 +368,8 @@ class AppHarness:
366
368
  state=self.app_instance._state,
367
369
  )
368
370
  if not isinstance(self.app_instance.state_manager, StateManagerRedis):
369
- raise RuntimeError("Failed to reset state manager.")
371
+ msg = "Failed to reset state manager."
372
+ raise RuntimeError(msg)
370
373
 
371
374
  def _start_frontend(self):
372
375
  # Set up the frontend.
@@ -406,7 +409,8 @@ class AppHarness:
406
409
  config.deploy_url = self.frontend_url
407
410
  break
408
411
  if self.frontend_url is None:
409
- raise RuntimeError("Frontend did not start")
412
+ msg = "Frontend did not start"
413
+ raise RuntimeError(msg)
410
414
 
411
415
  def consume_frontend_output():
412
416
  while True:
@@ -578,20 +582,23 @@ class AppHarness:
578
582
  TimeoutError: when server or sockets are not ready
579
583
  """
580
584
  if self.backend is None:
581
- raise RuntimeError("Backend is not running.")
585
+ msg = "Backend is not running."
586
+ raise RuntimeError(msg)
582
587
  backend = self.backend
583
588
  # check for servers to be initialized
584
589
  if not self._poll_for(
585
590
  target=lambda: getattr(backend, "servers", False),
586
591
  timeout=timeout,
587
592
  ):
588
- raise TimeoutError("Backend servers are not initialized.")
593
+ msg = "Backend servers are not initialized."
594
+ raise TimeoutError(msg)
589
595
  # check for sockets to be listening
590
596
  if not self._poll_for(
591
597
  target=lambda: getattr(backend.servers[0], "sockets", False),
592
598
  timeout=timeout,
593
599
  ):
594
- raise TimeoutError("Backend is not listening.")
600
+ msg = "Backend is not listening."
601
+ raise TimeoutError(msg)
595
602
  return backend.servers[0].sockets[0]
596
603
 
597
604
  def frontend(
@@ -619,12 +626,14 @@ class AppHarness:
619
626
  RuntimeError: when selenium is not importable or frontend is not running
620
627
  """
621
628
  if not has_selenium:
622
- raise RuntimeError(
629
+ msg = (
623
630
  "Frontend functionality requires `selenium` to be installed, "
624
631
  "and it could not be imported."
625
632
  )
633
+ raise RuntimeError(msg)
626
634
  if self.frontend_url is None:
627
- raise RuntimeError("Frontend is not running.")
635
+ msg = "Frontend is not running."
636
+ raise RuntimeError(msg)
628
637
  want_headless = False
629
638
  if environment.APP_HARNESS_HEADLESS.get():
630
639
  want_headless = True
@@ -650,7 +659,8 @@ class AppHarness:
650
659
  if want_headless:
651
660
  driver_options.add_argument("headless")
652
661
  if driver_options is None:
653
- raise RuntimeError(f"Could not determine options for {driver_clz}")
662
+ msg = f"Could not determine options for {driver_clz}"
663
+ raise RuntimeError(msg)
654
664
  if args := environment.APP_HARNESS_DRIVER_ARGS.get():
655
665
  for arg in args.split(","):
656
666
  driver_options.add_argument(arg)
@@ -680,7 +690,8 @@ class AppHarness:
680
690
  RuntimeError: when the app hasn't started running
681
691
  """
682
692
  if self.state_manager is None:
683
- raise RuntimeError("state_manager is not set.")
693
+ msg = "state_manager is not set."
694
+ raise RuntimeError(msg)
684
695
  try:
685
696
  return await self.state_manager.get_state(token)
686
697
  finally:
@@ -698,7 +709,8 @@ class AppHarness:
698
709
  RuntimeError: when the app hasn't started running
699
710
  """
700
711
  if self.state_manager is None:
701
- raise RuntimeError("state_manager is not set.")
712
+ msg = "state_manager is not set."
713
+ raise RuntimeError(msg)
702
714
  state = await self.get_state(token)
703
715
  for key, value in kwargs.items():
704
716
  setattr(state, key, value)
@@ -722,9 +734,11 @@ class AppHarness:
722
734
  RuntimeError: when the app hasn't started running
723
735
  """
724
736
  if self.state_manager is None:
725
- raise RuntimeError("state_manager is not set.")
737
+ msg = "state_manager is not set."
738
+ raise RuntimeError(msg)
726
739
  if self.app_instance is None:
727
- raise RuntimeError("App is not running.")
740
+ msg = "App is not running."
741
+ raise RuntimeError(msg)
728
742
  app_state_manager = self.app_instance.state_manager
729
743
  if isinstance(self.state_manager, StateManagerRedis):
730
744
  # Temporarily replace the app's state manager with our own, since
@@ -761,9 +775,8 @@ class AppHarness:
761
775
  target=lambda: element.text != exp_not_equal,
762
776
  timeout=timeout,
763
777
  ):
764
- raise TimeoutError(
765
- f"{element} content remains {exp_not_equal!r} while polling.",
766
- )
778
+ msg = f"{element} content remains {exp_not_equal!r} while polling."
779
+ raise TimeoutError(msg)
767
780
  return element.text
768
781
 
769
782
  def poll_for_value(
@@ -792,9 +805,8 @@ class AppHarness:
792
805
  target=lambda: element.get_attribute("value") not in exp_not_equal,
793
806
  timeout=timeout,
794
807
  ):
795
- raise TimeoutError(
796
- f"{element} content remains {exp_not_equal!r} while polling.",
797
- )
808
+ msg = f"{element} content remains {exp_not_equal!r} while polling."
809
+ raise TimeoutError(msg)
798
810
  return element.get_attribute("value")
799
811
 
800
812
  def poll_for_clients(self, timeout: TimeoutType = None) -> dict[str, BaseState]:
@@ -812,15 +824,18 @@ class AppHarness:
812
824
  ValueError: when the state_manager is not a memory state manager
813
825
  """
814
826
  if self.app_instance is None:
815
- raise RuntimeError("App is not running.")
827
+ msg = "App is not running."
828
+ raise RuntimeError(msg)
816
829
  state_manager = self.app_instance.state_manager
817
830
  if not isinstance(state_manager, (StateManagerMemory, StateManagerDisk)):
818
- raise ValueError("Only works with memory or disk state manager")
831
+ msg = "Only works with memory or disk state manager"
832
+ raise ValueError(msg)
819
833
  if not self._poll_for(
820
834
  target=lambda: state_manager.states,
821
835
  timeout=timeout,
822
836
  ):
823
- raise TimeoutError("No states were observed while polling.")
837
+ msg = "No states were observed while polling."
838
+ raise TimeoutError(msg)
824
839
  return state_manager.states
825
840
 
826
841
 
@@ -962,11 +977,13 @@ class AppHarnessProd(AppHarness):
962
977
  def _wait_frontend(self):
963
978
  self._poll_for(lambda: self.frontend_server is not None)
964
979
  if self.frontend_server is None or not self.frontend_server.socket.fileno():
965
- raise RuntimeError("Frontend did not start")
980
+ msg = "Frontend did not start"
981
+ raise RuntimeError(msg)
966
982
 
967
983
  def _start_backend(self):
968
984
  if self.app_asgi is None:
969
- raise RuntimeError("App was not initialized.")
985
+ msg = "App was not initialized."
986
+ raise RuntimeError(msg)
970
987
  environment.REFLEX_SKIP_COMPILE.set(True)
971
988
  self.backend = uvicorn.Server(
972
989
  uvicorn.Config(
reflex/utils/build.py CHANGED
@@ -132,7 +132,7 @@ def _zip(
132
132
  def zip_app(
133
133
  frontend: bool = True,
134
134
  backend: bool = True,
135
- zip_dest_dir: str | Path = Path.cwd(),
135
+ zip_dest_dir: str | Path | None = None,
136
136
  upload_db_file: bool = False,
137
137
  ):
138
138
  """Zip up the app.
@@ -143,6 +143,7 @@ def zip_app(
143
143
  zip_dest_dir: The directory to export the zip file to.
144
144
  upload_db_file: Whether to upload the database file.
145
145
  """
146
+ zip_dest_dir = zip_dest_dir or Path.cwd()
146
147
  zip_dest_dir = Path(zip_dest_dir)
147
148
  files_to_exclude = {
148
149
  constants.ComponentName.FRONTEND.zip(),