Skip to content

Commit 69eae3f

Browse files
adhami3310masenf
andauthored
crack down on sets for uniqueness (#5316)
* crack down on sets for uniqueness * remove extra set Co-authored-by: Masen Furer <m_github@0x26.net> --------- Co-authored-by: Masen Furer <m_github@0x26.net>
1 parent 854ccd0 commit 69eae3f

File tree

6 files changed

+21
-29
lines changed

6 files changed

+21
-29
lines changed

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
@@ -2547,7 +2547,9 @@ def _get_hook_deps(hook: str) -> list[str]:
25472547
return [var_name]
25482548

25492549
@staticmethod
2550-
def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str]:
2550+
def _get_deps_from_event_trigger(
2551+
event: EventChain | EventSpec | Var,
2552+
) -> dict[str, None]:
25512553
"""Get the dependencies accessed by event triggers.
25522554
25532555
Args:
@@ -2557,7 +2559,7 @@ def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str
25572559
The dependencies accessed by the event triggers.
25582560
"""
25592561
events: list = [event]
2560-
deps = set()
2562+
deps = {}
25612563

25622564
if isinstance(event, EventChain):
25632565
events.extend(event.events)
@@ -2568,7 +2570,7 @@ def _get_deps_from_event_trigger(event: EventChain | EventSpec | Var) -> set[str
25682570
for a in arg:
25692571
var_datas = VarData.merge(a._get_all_var_data())
25702572
if var_datas and var_datas.deps is not None:
2571-
deps |= {str(dep) for dep in var_datas.deps}
2573+
deps |= {str(dep): None for dep in var_datas.deps}
25722574
return deps
25732575

25742576
@classmethod
@@ -2785,27 +2787,23 @@ def empty_component() -> Component:
27852787
return Bare.create("")
27862788

27872789

2788-
def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) -> Var:
2790+
def render_dict_to_var(tag: dict | Component | str) -> Var:
27892791
"""Convert a render dict to a Var.
27902792
27912793
Args:
27922794
tag: The render dict.
2793-
imported_names: The names of the imported components.
27942795
27952796
Returns:
27962797
The Var.
27972798
"""
27982799
if not isinstance(tag, dict):
27992800
if isinstance(tag, Component):
2800-
return render_dict_to_var(tag.render(), imported_names)
2801+
return render_dict_to_var(tag.render())
28012802
return Var.create(tag)
28022803

28032804
if "iterable" in tag:
28042805
function_return = LiteralArrayVar.create(
2805-
[
2806-
render_dict_to_var(child.render(), imported_names)
2807-
for child in tag["children"]
2808-
]
2806+
[render_dict_to_var(child.render()) for child in tag["children"]]
28092807
)
28102808

28112809
func = ArgsFunctionOperation.create(
@@ -2823,7 +2821,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
28232821
if tag["name"] == "match":
28242822
element = tag["cond"]
28252823

2826-
conditionals = render_dict_to_var(tag["default"], imported_names)
2824+
conditionals = render_dict_to_var(tag["default"])
28272825

28282826
for case in tag["match_cases"][::-1]:
28292827
condition = case[0].to_string() == element.to_string()
@@ -2832,7 +2830,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
28322830

28332831
conditionals = ternary_operation(
28342832
condition,
2835-
render_dict_to_var(case[-1], imported_names),
2833+
render_dict_to_var(case[-1]),
28362834
conditionals,
28372835
)
28382836

@@ -2841,8 +2839,8 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
28412839
if "cond" in tag:
28422840
return ternary_operation(
28432841
tag["cond"],
2844-
render_dict_to_var(tag["true_value"], imported_names),
2845-
render_dict_to_var(tag["false_value"], imported_names)
2842+
render_dict_to_var(tag["true_value"]),
2843+
render_dict_to_var(tag["false_value"])
28462844
if tag["false_value"] is not None
28472845
else LiteralNoneVar.create(),
28482846
)
@@ -2860,7 +2858,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
28602858
tag_name,
28612859
props,
28622860
*([Var(contents)] if contents is not None else []),
2863-
*[render_dict_to_var(child, imported_names) for child in tag["children"]],
2861+
*[render_dict_to_var(child) for child in tag["children"]],
28642862
)
28652863

28662864

@@ -2881,13 +2879,7 @@ def _cached_var_name(self) -> str:
28812879
Returns:
28822880
The name of the var.
28832881
"""
2884-
var_data = self._get_all_var_data()
2885-
if var_data is not None:
2886-
# flatten imports
2887-
imported_names = {j.alias or j.name for i in var_data.imports for j in i[1]}
2888-
else:
2889-
imported_names = set()
2890-
return str(render_dict_to_var(self._var_value.render(), imported_names))
2882+
return str(render_dict_to_var(self._var_value.render()))
28912883

28922884
@cached_property_no_lock
28932885
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ def merge(*all: VarData | None) -> VarData | None:
239239
deps = [dep for var_data in all_var_datas for dep in var_data.deps]
240240

241241
positions = list(
242-
{
242+
dict.fromkeys(
243243
var_data.position
244244
for var_data in all_var_datas
245245
if var_data.position is not None
246-
}
246+
)
247247
)
248248
if positions:
249249
if len(positions) > 1:

0 commit comments

Comments
 (0)