Skip to content

Commit e058afc

Browse files
committed
crack down on sets for uniqueness
1 parent 69ca396 commit e058afc

6 files changed

Lines changed: 26 additions & 32 deletions

File tree

reflex/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ def _submit_work(fn: Callable[..., tuple[str, str]], *args, **kwargs):
14431443
custom_components_output,
14441444
custom_components_result,
14451445
custom_components_imports,
1446-
) = compiler.compile_components(set(CUSTOM_COMPONENTS.values()))
1446+
) = compiler.compile_components(dict.fromkeys(CUSTOM_COMPONENTS.values()))
14471447
compile_results.append((custom_components_output, custom_components_result))
14481448
all_imports.update(custom_components_imports)
14491449

reflex/compiler/compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _compile_component(component: Component | StatefulComponent) -> str:
326326

327327

328328
def _compile_components(
329-
components: set[CustomComponent],
329+
components: Iterable[CustomComponent],
330330
) -> tuple[str, dict[str, list[ImportVar]]]:
331331
"""Compile the components.
332332
@@ -572,7 +572,7 @@ def compile_page(
572572

573573

574574
def compile_components(
575-
components: set[CustomComponent],
575+
components: Iterable[CustomComponent],
576576
) -> tuple[str, str, dict[str, list[ImportVar]]]:
577577
"""Compile the custom components.
578578

reflex/compiler/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def compile_import_statement(fields: list[ImportVar]) -> tuple[str, list[str]]:
6666
default = next(iter({field.name for field in defaults}), "")
6767
rest = {field.name for field in fields_set - defaults}
6868

69-
return default, list(rest)
69+
return default, sorted(rest)
7070

7171

7272
def validate_imports(import_dict: ParsedImportDict):

reflex/components/component.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,9 @@ def _get_hook_deps(hook: str) -> list[str]:
22612261
return [var_name]
22622262

22632263
@staticmethod
2264-
def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str]:
2264+
def _get_deps_from_event_trigger(
2265+
event: EventChain | EventSpec | Var,
2266+
) -> dict[str, None]:
22652267
"""Get the dependencies accessed by event triggers.
22662268
22672269
Args:
@@ -2271,7 +2273,7 @@ def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str
22712273
The dependencies accessed by the event triggers.
22722274
"""
22732275
events: list = [event]
2274-
deps = set()
2276+
deps = {}
22752277

22762278
if isinstance(event, EventChain):
22772279
events.extend(event.events)
@@ -2282,7 +2284,7 @@ def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str
22822284
for a in arg:
22832285
var_datas = VarData.merge(a._get_all_var_data())
22842286
if var_datas and var_datas.deps is not None:
2285-
deps |= {str(dep) for dep in var_datas.deps}
2287+
deps |= {str(dep): None for dep in var_datas.deps}
22862288
return deps
22872289

22882290
@classmethod
@@ -2499,27 +2501,23 @@ def empty_component() -> Component:
24992501
return Bare.create("")
25002502

25012503

2502-
def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) -> Var:
2504+
def render_dict_to_var(tag: dict | Component | str) -> Var:
25032505
"""Convert a render dict to a Var.
25042506
25052507
Args:
25062508
tag: The render dict.
2507-
imported_names: The names of the imported components.
25082509
25092510
Returns:
25102511
The Var.
25112512
"""
25122513
if not isinstance(tag, dict):
25132514
if isinstance(tag, Component):
2514-
return render_dict_to_var(tag.render(), imported_names)
2515+
return render_dict_to_var(tag.render())
25152516
return Var.create(tag)
25162517

25172518
if "iterable" in tag:
25182519
function_return = LiteralArrayVar.create(
2519-
[
2520-
render_dict_to_var(child.render(), imported_names)
2521-
for child in tag["children"]
2522-
]
2520+
[render_dict_to_var(child.render()) for child in tag["children"]]
25232521
)
25242522

25252523
func = ArgsFunctionOperation.create(
@@ -2537,7 +2535,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
25372535
if tag["name"] == "match":
25382536
element = tag["cond"]
25392537

2540-
conditionals = render_dict_to_var(tag["default"], imported_names)
2538+
conditionals = render_dict_to_var(tag["default"])
25412539

25422540
for case in tag["match_cases"][::-1]:
25432541
condition = case[0].to_string() == element.to_string()
@@ -2546,7 +2544,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
25462544

25472545
conditionals = ternary_operation(
25482546
condition,
2549-
render_dict_to_var(case[-1], imported_names),
2547+
render_dict_to_var(case[-1]),
25502548
conditionals,
25512549
)
25522550

@@ -2555,8 +2553,8 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
25552553
if "cond" in tag:
25562554
return ternary_operation(
25572555
tag["cond"],
2558-
render_dict_to_var(tag["true_value"], imported_names),
2559-
render_dict_to_var(tag["false_value"], imported_names)
2556+
render_dict_to_var(tag["true_value"]),
2557+
render_dict_to_var(tag["false_value"])
25602558
if tag["false_value"] is not None
25612559
else LiteralNoneVar.create(),
25622560
)
@@ -2574,7 +2572,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
25742572
tag_name,
25752573
props,
25762574
*([Var(contents)] if contents is not None else []),
2577-
*[render_dict_to_var(child, imported_names) for child in tag["children"]],
2575+
*[render_dict_to_var(child) for child in tag["children"]],
25782576
)
25792577

25802578

@@ -2595,13 +2593,7 @@ def _cached_var_name(self) -> str:
25952593
Returns:
25962594
The name of the var.
25972595
"""
2598-
var_data = self._get_all_var_data()
2599-
if var_data is not None:
2600-
# flatten imports
2601-
imported_names = {j.alias or j.name for i in var_data.imports for j in i[1]}
2602-
else:
2603-
imported_names = set()
2604-
return str(render_dict_to_var(self._var_value.render(), imported_names))
2596+
return str(render_dict_to_var(self._var_value.render()))
26052597

26062598
@cached_property_no_lock
26072599
def _cached_get_all_var_data(self) -> VarData | None:

reflex/utils/prerequisites.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def _update_next_config(
11201120

11211121
if transpile_packages:
11221122
next_config["transpilePackages"] = list(
1123-
{format_library_name(p) for p in transpile_packages}
1123+
dict.fromkeys([format_library_name(p) for p in transpile_packages])
11241124
)
11251125
if export:
11261126
next_config["output"] = "export"

reflex/vars/base.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,13 @@ def merge(*all: VarData | None) -> VarData | None:
233233
deps = [dep for var_data in all_var_datas for dep in var_data.deps]
234234

235235
positions = list(
236-
{
237-
var_data.position
238-
for var_data in all_var_datas
239-
if var_data.position is not None
240-
}
236+
dict.fromkeys(
237+
{
238+
var_data.position
239+
for var_data in all_var_datas
240+
if var_data.position is not None
241+
}
242+
)
241243
)
242244
if positions:
243245
if len(positions) > 1:

0 commit comments

Comments
 (0)