reflex 0.7.0a3__py3-none-any.whl → 0.7.0a4__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.

reflex/event.py CHANGED
@@ -26,6 +26,7 @@ from typing import (
26
26
 
27
27
  from typing_extensions import (
28
28
  Protocol,
29
+ Self,
29
30
  TypeAliasType,
30
31
  TypedDict,
31
32
  TypeVar,
@@ -110,7 +111,7 @@ class EventActionsMixin:
110
111
  event_actions: Dict[str, Union[bool, int]] = dataclasses.field(default_factory=dict)
111
112
 
112
113
  @property
113
- def stop_propagation(self):
114
+ def stop_propagation(self) -> Self:
114
115
  """Stop the event from bubbling up the DOM tree.
115
116
 
116
117
  Returns:
@@ -122,7 +123,7 @@ class EventActionsMixin:
122
123
  )
123
124
 
124
125
  @property
125
- def prevent_default(self):
126
+ def prevent_default(self) -> Self:
126
127
  """Prevent the default behavior of the event.
127
128
 
128
129
  Returns:
@@ -133,7 +134,7 @@ class EventActionsMixin:
133
134
  event_actions={"preventDefault": True, **self.event_actions},
134
135
  )
135
136
 
136
- def throttle(self, limit_ms: int):
137
+ def throttle(self, limit_ms: int) -> Self:
137
138
  """Throttle the event handler.
138
139
 
139
140
  Args:
@@ -147,7 +148,7 @@ class EventActionsMixin:
147
148
  event_actions={"throttle": limit_ms, **self.event_actions},
148
149
  )
149
150
 
150
- def debounce(self, delay_ms: int):
151
+ def debounce(self, delay_ms: int) -> Self:
151
152
  """Debounce the event handler.
152
153
 
153
154
  Args:
@@ -162,7 +163,7 @@ class EventActionsMixin:
162
163
  )
163
164
 
164
165
  @property
165
- def temporal(self):
166
+ def temporal(self) -> Self:
166
167
  """Do not queue the event if the backend is down.
167
168
 
168
169
  Returns:
@@ -1773,7 +1774,7 @@ V4 = TypeVar("V4")
1773
1774
  V5 = TypeVar("V5")
1774
1775
 
1775
1776
 
1776
- class EventCallback(Generic[Unpack[P]]):
1777
+ class EventCallback(Generic[Unpack[P]], EventActionsMixin):
1777
1778
  """A descriptor that wraps a function to be used as an event."""
1778
1779
 
1779
1780
  def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
@@ -1784,24 +1785,6 @@ class EventCallback(Generic[Unpack[P]]):
1784
1785
  """
1785
1786
  self.func = func
1786
1787
 
1787
- @property
1788
- def prevent_default(self):
1789
- """Prevent default behavior.
1790
-
1791
- Returns:
1792
- The event callback with prevent default behavior.
1793
- """
1794
- return self
1795
-
1796
- @property
1797
- def stop_propagation(self):
1798
- """Stop event propagation.
1799
-
1800
- Returns:
1801
- The event callback with stop propagation behavior.
1802
- """
1803
- return self
1804
-
1805
1788
  @overload
1806
1789
  def __call__(
1807
1790
  self: EventCallback[Unpack[Q]],
reflex/utils/console.py CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import contextlib
5
6
  import inspect
6
7
  import shutil
8
+ import time
7
9
  from pathlib import Path
8
10
  from types import FrameType
9
11
 
@@ -317,3 +319,20 @@ def status(*args, **kwargs):
317
319
  A new status.
318
320
  """
319
321
  return _console.status(*args, **kwargs)
322
+
323
+
324
+ @contextlib.contextmanager
325
+ def timing(msg: str):
326
+ """Create a context manager to time a block of code.
327
+
328
+ Args:
329
+ msg: The message to display.
330
+
331
+ Yields:
332
+ None.
333
+ """
334
+ start = time.time()
335
+ try:
336
+ yield
337
+ finally:
338
+ debug(f"[white]\\[timing] {msg}: {time.time() - start:.2f}s[/white]")
reflex/utils/imports.py CHANGED
@@ -109,6 +109,9 @@ class ImportVar:
109
109
  # whether this import should be rendered or not
110
110
  render: Optional[bool] = True
111
111
 
112
+ # The path of the package to import from.
113
+ package_path: str = "/"
114
+
112
115
  # whether this import package should be added to transpilePackages in next.config.js
113
116
  # https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages
114
117
  transpile: Optional[bool] = False
reflex/utils/path_ops.py CHANGED
@@ -245,3 +245,33 @@ def find_replace(directory: str | Path, find: str, replace: str):
245
245
  text = filepath.read_text(encoding="utf-8")
246
246
  text = re.sub(find, replace, text)
247
247
  filepath.write_text(text, encoding="utf-8")
248
+
249
+
250
+ def update_directory_tree(src: Path, dest: Path):
251
+ """Recursively copies a directory tree from src to dest.
252
+ Only copies files if the destination file is missing or modified earlier than the source file.
253
+
254
+ Args:
255
+ src: Source directory
256
+ dest: Destination directory
257
+
258
+ Raises:
259
+ ValueError: If the source is not a directory
260
+ """
261
+ if not src.is_dir():
262
+ raise ValueError(f"Source {src} is not a directory")
263
+
264
+ # Ensure the destination directory exists
265
+ dest.mkdir(parents=True, exist_ok=True)
266
+
267
+ for item in src.iterdir():
268
+ dest_item = dest / item.name
269
+
270
+ if item.is_dir():
271
+ # Recursively copy subdirectories
272
+ update_directory_tree(item, dest_item)
273
+ elif item.is_file() and (
274
+ not dest_item.exists() or item.stat().st_mtime > dest_item.stat().st_mtime
275
+ ):
276
+ # Copy file if it doesn't exist in the destination or is older than the source
277
+ shutil.copy2(item, dest_item)
reflex/vars/base.py CHANGED
@@ -2238,6 +2238,27 @@ class ComputedVar(Var[RETURN_TYPE]):
2238
2238
  owner: Type,
2239
2239
  ) -> ArrayVar[tuple[LIST_INSIDE, ...]]: ...
2240
2240
 
2241
+ @overload
2242
+ def __get__(
2243
+ self: ComputedVar[BASE_TYPE],
2244
+ instance: None,
2245
+ owner: Type,
2246
+ ) -> ObjectVar[BASE_TYPE]: ...
2247
+
2248
+ @overload
2249
+ def __get__(
2250
+ self: ComputedVar[SQLA_TYPE],
2251
+ instance: None,
2252
+ owner: Type,
2253
+ ) -> ObjectVar[SQLA_TYPE]: ...
2254
+
2255
+ if TYPE_CHECKING:
2256
+
2257
+ @overload
2258
+ def __get__(
2259
+ self: ComputedVar[DATACLASS_TYPE], instance: None, owner: Any
2260
+ ) -> ObjectVar[DATACLASS_TYPE]: ...
2261
+
2241
2262
  @overload
2242
2263
  def __get__(self, instance: None, owner: Type) -> ComputedVar[RETURN_TYPE]: ...
2243
2264
 
@@ -2484,6 +2505,27 @@ class AsyncComputedVar(ComputedVar[RETURN_TYPE]):
2484
2505
  owner: Type,
2485
2506
  ) -> ArrayVar[tuple[LIST_INSIDE, ...]]: ...
2486
2507
 
2508
+ @overload
2509
+ def __get__(
2510
+ self: AsyncComputedVar[BASE_TYPE],
2511
+ instance: None,
2512
+ owner: Type,
2513
+ ) -> ObjectVar[BASE_TYPE]: ...
2514
+
2515
+ @overload
2516
+ def __get__(
2517
+ self: AsyncComputedVar[SQLA_TYPE],
2518
+ instance: None,
2519
+ owner: Type,
2520
+ ) -> ObjectVar[SQLA_TYPE]: ...
2521
+
2522
+ if TYPE_CHECKING:
2523
+
2524
+ @overload
2525
+ def __get__(
2526
+ self: AsyncComputedVar[DATACLASS_TYPE], instance: None, owner: Any
2527
+ ) -> ObjectVar[DATACLASS_TYPE]: ...
2528
+
2487
2529
  @overload
2488
2530
  def __get__(self, instance: None, owner: Type) -> AsyncComputedVar[RETURN_TYPE]: ...
2489
2531
 
reflex/vars/object.py CHANGED
@@ -22,7 +22,12 @@ from typing_extensions import is_typeddict
22
22
 
23
23
  from reflex.utils import types
24
24
  from reflex.utils.exceptions import VarAttributeError
25
- from reflex.utils.types import GenericType, get_attribute_access_type, get_origin
25
+ from reflex.utils.types import (
26
+ GenericType,
27
+ get_attribute_access_type,
28
+ get_origin,
29
+ safe_issubclass,
30
+ )
26
31
 
27
32
  from .base import (
28
33
  CachedVarOperation,
@@ -187,10 +192,14 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
187
192
  Returns:
188
193
  The item from the object.
189
194
  """
195
+ from .sequence import LiteralStringVar
196
+
190
197
  if not isinstance(key, (StringVar, str, int, NumberVar)) or (
191
198
  isinstance(key, NumberVar) and key._is_strict_float()
192
199
  ):
193
200
  raise_unsupported_operand_types("[]", (type(self), type(key)))
201
+ if isinstance(key, str) and isinstance(Var.create(key), LiteralStringVar):
202
+ return self.__getattr__(key)
194
203
  return ObjectItemOperation.create(self, key).guess_type()
195
204
 
196
205
  # NoReturn is used here to catch when key value is Any
@@ -260,12 +269,12 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
260
269
  if types.is_optional(var_type):
261
270
  var_type = get_args(var_type)[0]
262
271
 
263
- fixed_type = var_type if isclass(var_type) else get_origin(var_type)
272
+ fixed_type = get_origin(var_type) or var_type
264
273
 
265
274
  if (
266
- (isclass(fixed_type) and not issubclass(fixed_type, Mapping))
275
+ is_typeddict(fixed_type)
276
+ or (isclass(fixed_type) and not safe_issubclass(fixed_type, Mapping))
267
277
  or (fixed_type in types.UnionTypes)
268
- or is_typeddict(fixed_type)
269
278
  ):
270
279
  attribute_type = get_attribute_access_type(var_type, name)
271
280
  if attribute_type is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: reflex
3
- Version: 0.7.0a3
3
+ Version: 0.7.0a4
4
4
  Summary: Web apps in pure Python.
5
5
  License: Apache-2.0
6
6
  Keywords: web,framework
@@ -40,7 +40,7 @@ reflex/__init__.py,sha256=vaj8MEv0GwrvMzAYQeayyMvRE4TuAD1Xx3pDpjiY3sA,10289
40
40
  reflex/__init__.pyi,sha256=fOSkQZ2RHNzoLXqoVy-2gC5ys45Erxia1yPp34UFk_k,11235
41
41
  reflex/__main__.py,sha256=6cVrGEyT3j3tEvlEVUatpaYfbB5EF3UVY-6vc_Z7-hw,108
42
42
  reflex/admin.py,sha256=_3pkkauMiTGJJ0kwAEBnsUWAgZZ_1WNnCaaObbhpmUI,374
43
- reflex/app.py,sha256=Kdt-6MRvnSvi8aPjNUdKc5Elwp3vYESEDMZYrICV3oU,61428
43
+ reflex/app.py,sha256=ANWHGuxJs2_QAOgW63_7NDo8fNlcL8AUPss3CiVJSYM,62300
44
44
  reflex/app_mixins/__init__.py,sha256=Oegz3-gZLP9p2OAN5ALNbsgxuNQfS6lGZgQA8cc-9mQ,137
45
45
  reflex/app_mixins/lifespan.py,sha256=Xs5KiidoyO921oaBuEg7zaR8B1_SPYDZLouel6u9PRo,3298
46
46
  reflex/app_mixins/middleware.py,sha256=lB8I67SEbqcJhp3aqMLZFIZekCYKeMby-Ph2sedIYJI,3349
@@ -51,7 +51,7 @@ reflex/base.py,sha256=2ft5udkFRgZpSA8WbkkCk4tUumj6YsGOUM-RDYDCa20,4236
51
51
  reflex/compiler/__init__.py,sha256=r8jqmDSFf09iV2lHlNhfc9XrTLjNxfDNwPYlxS4cmHE,27
52
52
  reflex/compiler/compiler.py,sha256=8fa-IvHJKpk3URrfEjY049Zv220o4BEZ8Kokdkd4QhY,21046
53
53
  reflex/compiler/templates.py,sha256=XsimfIuF-aYnk7r1LfLVJWW8447Lra32cxZBrw20YnU,5900
54
- reflex/compiler/utils.py,sha256=6UfBj9I8Y_kZ1HQj6j-wWAV2FoSuPTbI-n0REs6iWs4,15902
54
+ reflex/compiler/utils.py,sha256=HPDt64CqgWFVUi9tTPMGfSKV0E3M6RXg1jzzRHVWViM,16295
55
55
  reflex/components/__init__.py,sha256=zbIXThv1WPI0FdIGf9G9RAmGoCRoGy7nHcSZ8K5D5bA,624
56
56
  reflex/components/__init__.pyi,sha256=qoj1zIWaitcZOGcJ6k7wuGJk_GAJCE9Xtx8CeRVrvoE,861
57
57
  reflex/components/base/__init__.py,sha256=QIOxOPT87WrSE4TSHAsZ-358VzvUXAe1w8vWogQ3Uuo,730
@@ -163,9 +163,9 @@ reflex/components/next/link.py,sha256=YYhkgkHGqvyf5JGv-ujatzp_nOqEUAxWY9FIWk7r39
163
163
  reflex/components/next/link.pyi,sha256=E63U9yoAHdtlvucg-mX1O58j4uWpIW8433DFxFH6YBI,2423
164
164
  reflex/components/next/video.py,sha256=GngxgHvAfGwRHkPUBNp6_GfGarP5mMN6KFA_-VizDOI,735
165
165
  reflex/components/next/video.pyi,sha256=OqvLHkAzgF7-7lb7uaE-8Mfg60XZXdkU4jFnUMapXi4,2364
166
- reflex/components/plotly/__init__.py,sha256=OX-Ly11fIg0uRTQHfqNVKV4M9xqMqLOqXzZIfKNYE0w,77
167
- reflex/components/plotly/plotly.py,sha256=fG4rGIjOgaYD_0V9JW_5jVezMOZf_MGEuxFZ_V5Zf8s,8775
168
- reflex/components/plotly/plotly.pyi,sha256=hQN2kTFTalVe-5lTtxmLdEDvk4fVUo0ovbrcaNjJT1E,6695
166
+ reflex/components/plotly/__init__.py,sha256=6B_woBJhkrVA9O_AbOTbsA_SxWsqjicYHmLA9FLjGfU,650
167
+ reflex/components/plotly/plotly.py,sha256=bv9uvQw0EHhwcgiYHotPBWoq8FMSoCGB7TqbD3lHuMQ,15343
168
+ reflex/components/plotly/plotly.pyi,sha256=VGJggBUIodQTehSCNgdrkY9eDlwWZZaUXqIhEh0pQOc,47888
169
169
  reflex/components/props.py,sha256=8F2ZNeF16BDiTh-E4F-U_vks41BMJgmkTM7xbjGvfOA,2593
170
170
  reflex/components/radix/__init__.py,sha256=fRsLvIO3MrTtPOXtmnxYDB9phvzlcbyB_utgpafYMho,474
171
171
  reflex/components/radix/__init__.pyi,sha256=YpWw_k35yv_Yq_0RZNCb52fJZ3dANWAnQllhVoVCWEE,3988
@@ -342,7 +342,7 @@ reflex/constants/style.py,sha256=EPgRYHhAlcrPUBc2HkDTdTj-Q0uDAXHlq8Sp6D35Zf4,475
342
342
  reflex/constants/utils.py,sha256=HGOSq9c-xGbCb1xoLAGLBdc-FOE8iuBzvuU24zSfsV0,789
343
343
  reflex/custom_components/__init__.py,sha256=R4zsvOi4dfPmHc18KEphohXnQFBPnUCb50cMR5hSLDE,36
344
344
  reflex/custom_components/custom_components.py,sha256=alW_lKBVemMQhuGobzeycgd34mvz37kPNTytLfLplmQ,33414
345
- reflex/event.py,sha256=aXVTgP8jFcd8G4-X2JviOQTcQc0B-dGz6mu7ocyPRqY,61225
345
+ reflex/event.py,sha256=JLE5y2pGgUiVmxMReTKNSkcw6fCkONqjXuN4tM3jkts,60904
346
346
  reflex/experimental/__init__.py,sha256=bvJ6qFeO3xT3L-8IBtk4ecoi5rda3EDvblgNP60yhEo,2206
347
347
  reflex/experimental/client_state.py,sha256=5lmCM7fzEtJp5eegUCoygJRYXf6f1U9UiFyuWxsznbs,9906
348
348
  reflex/experimental/hooks.py,sha256=CHYGrAE5t8riltrJmDFgJ4D2Vhmhw-y3B3MSGNlOQow,2366
@@ -369,15 +369,15 @@ reflex/utils/__init__.py,sha256=y-AHKiRQAhk2oAkvn7W8cRVTZVK625ff8tTwvZtO7S4,24
369
369
  reflex/utils/build.py,sha256=5S8zQYiSp2czardXzwY060qScxNDiYWabUzs8elQivE,8522
370
370
  reflex/utils/codespaces.py,sha256=TzDK--pHwP4r8Nzl0iB_8r-cOFmmL6nHfZ9xRQHA-KY,2754
371
371
  reflex/utils/compat.py,sha256=aSJH_M6iomgHPQ4onQ153xh1MWqPi3HSYDzE68N6gZM,2635
372
- reflex/utils/console.py,sha256=UeapvxGOcISv77tylHxech5F5R53mmNk4cnwcTseD8Q,8948
372
+ reflex/utils/console.py,sha256=jGPhAy-BBBRLEy0DRD8EoP-2ziPR4-N5CK53wUethFU,9307
373
373
  reflex/utils/exceptions.py,sha256=qL5E6F-lKcY7FrYJwKg-LjdvuugYnjszdnbfWkLemsE,7844
374
374
  reflex/utils/exec.py,sha256=bc966tpJ8rUh9J8vhZc3txLGp8nAdmUCn76IKLmY1hU,16066
375
375
  reflex/utils/export.py,sha256=wsyC6Atsu8LBZlrX0PhjnisMwhFycf4a3WH8DG1dam0,2567
376
376
  reflex/utils/format.py,sha256=j56pM45c_-nq8Fnw8Q1z20Y0wFJ32fPpCPFLgH_xCQM,19876
377
- reflex/utils/imports.py,sha256=CreBXamunK4I8BcBY-ET0P3kHLDZim1hV8ESoOBkOwo,3899
377
+ reflex/utils/imports.py,sha256=8lTJ8qCJlMUlQnZssOv0l2nntuTfGfLsLqkJAS5JTbA,3974
378
378
  reflex/utils/lazy_loader.py,sha256=-3DcwIqHNft2fb1ikgDYAMiEwNfbiWfrTBAf1gEVX2o,1367
379
379
  reflex/utils/net.py,sha256=0Yd9OLK8R_px2sqnqrDkTky6hYHtG2pEDvvilOjDfjc,1219
380
- reflex/utils/path_ops.py,sha256=iX92VuUD0xu0FTtF8_azWELF33n9P6C0mOT0WFfThCw,6137
380
+ reflex/utils/path_ops.py,sha256=2RBdkMmH4LKvdP0y1lTrQNqk6yw8ZHdcU7bu4N_gjVI,7135
381
381
  reflex/utils/prerequisites.py,sha256=19rcXlTUBhqVnYIFVnYcwgRQTie6_5lFyAU9OHVeQSA,65652
382
382
  reflex/utils/processes.py,sha256=h_vXmQdInVCaCQ1cGgIQd4x5CbzYRSFy6n1U4iWkMy8,13729
383
383
  reflex/utils/pyi_generator.py,sha256=6BVJ1KrLH8WvfYjBVm5-zjI6-Zdhzngp5ubkixsCIl4,41240
@@ -387,15 +387,15 @@ reflex/utils/serializers.py,sha256=xQjEiIqZS0tjxuEjqETXikePzSAbCxC6g_JnzNYk2s4,1
387
387
  reflex/utils/telemetry.py,sha256=PfbtZKtAaP_ufad5ZNqJYrtvkjDrqEFUGy9We9-B0pg,5804
388
388
  reflex/utils/types.py,sha256=kZHLmRibRnTRex5cbjlnFqsYpi2CSbfsfOQ_vS70cxU,27124
389
389
  reflex/vars/__init__.py,sha256=2Kv6Oh9g3ISZFESjL1al8KiO7QBZUXmLKGMCBsP-DoY,1243
390
- reflex/vars/base.py,sha256=nvg4X1_lyy2lBplZUiYUhfG_JxVFpJxZYHRd8vdsEoM,99185
390
+ reflex/vars/base.py,sha256=vsKm-UHWFf6keupqgC_x4B8QyILH1xgJwMjV4-ow9Q4,100162
391
391
  reflex/vars/datetime.py,sha256=6j63p5uZiWLldiIl3VVh9jWghuW1_GyBevyy2b4rdr4,5803
392
392
  reflex/vars/dep_tracking.py,sha256=kluvF4Pfbpdqf0GcpmYHjT1yP-D1erAzaSQP6qIxjB0,13846
393
393
  reflex/vars/function.py,sha256=v2W5JHgCK9Afu2mobFeoj03G6tbih1Y-wM7LQBwA9vU,14777
394
394
  reflex/vars/number.py,sha256=rVybcAoMOOFsWAbA_BZN3GVx9p4W_YPLHVYRCJqti04,27861
395
- reflex/vars/object.py,sha256=bolalu-v36VT_vwVrX5dh_o6x_zkvAUZlYZbrDrNHag,14841
395
+ reflex/vars/object.py,sha256=jfvxtrklztDtbD2zgNVNCZZE6X6HQMB6yJHPhtb0hUo,15033
396
396
  reflex/vars/sequence.py,sha256=GiSXbOIcoy7VSrecuBjbhg5G4QTjFV0Rcfn5T0EsecA,52032
397
- reflex-0.7.0a3.dist-info/LICENSE,sha256=dw3zLrp9f5ObD7kqS32vWfhcImfO52PMmRqvtxq_YEE,11358
398
- reflex-0.7.0a3.dist-info/METADATA,sha256=tqTL_Z0lxST9pxOPdnVgOWcXzYEm76vsJQfeWXMvTPI,12073
399
- reflex-0.7.0a3.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
400
- reflex-0.7.0a3.dist-info/entry_points.txt,sha256=H1Z5Yat_xJfy0dRT1Frk2PkO_p41Xy7fCKlj4FcdL9o,44
401
- reflex-0.7.0a3.dist-info/RECORD,,
397
+ reflex-0.7.0a4.dist-info/LICENSE,sha256=dw3zLrp9f5ObD7kqS32vWfhcImfO52PMmRqvtxq_YEE,11358
398
+ reflex-0.7.0a4.dist-info/METADATA,sha256=fih2rIyNIUOKlUu7n5bmWVhNYzArcwYarcMtJ6wzFAI,12073
399
+ reflex-0.7.0a4.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
400
+ reflex-0.7.0a4.dist-info/entry_points.txt,sha256=H1Z5Yat_xJfy0dRT1Frk2PkO_p41Xy7fCKlj4FcdL9o,44
401
+ reflex-0.7.0a4.dist-info/RECORD,,