Skip to content

Commit 118c5e8

Browse files
committed
optimize _iter_parent_classes_with_method a tad bit
1 parent 689ef20 commit 118c5e8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

reflex/components/component.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,20 +1497,21 @@ def _iter_parent_classes_names(cls) -> Iterator[str]:
14971497
yield clz.__name__
14981498

14991499
@classmethod
1500-
def _iter_parent_classes_with_method(cls, method: str) -> Iterator[type[Component]]:
1500+
def _iter_parent_classes_with_method(cls, method: str) -> Sequence[type[Component]]:
15011501
"""Iterate through parent classes that define a given method.
15021502
15031503
Used for handling the `add_*` API functions that internally simulate a super() call chain.
15041504
15051505
Args:
15061506
method: The method to look for.
15071507
1508-
Yields:
1509-
The parent classes that define the method (differently than the base).
1508+
Returns:
1509+
A sequence of parent classes that define the method (differently than the base).
15101510
"""
15111511
seen_methods = (
15121512
{getattr(Component, method)} if hasattr(Component, method) else set()
15131513
)
1514+
clzs: list[type[Component]] = []
15141515
for clz in cls.mro():
15151516
if clz is Component:
15161517
break
@@ -1520,7 +1521,8 @@ def _iter_parent_classes_with_method(cls, method: str) -> Iterator[type[Componen
15201521
if not callable(method_func) or method_func in seen_methods:
15211522
continue
15221523
seen_methods.add(method_func)
1523-
yield clz
1524+
clzs.append(clz)
1525+
return clzs
15241526

15251527
def _get_custom_code(self) -> str | None:
15261528
"""Get custom code for the component.
@@ -1673,7 +1675,7 @@ def _get_imports(self) -> ParsedImportDict:
16731675
return imports.merge_parsed_imports(
16741676
self._get_dependencies_imports(),
16751677
self._get_hooks_imports(),
1676-
{**_imports},
1678+
_imports,
16771679
event_imports,
16781680
var_imports,
16791681
imports.merge_imports(*added_import_dicts),

0 commit comments

Comments
 (0)