Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jul 22, 2024
1 parent 56e00b0 commit 23ab58c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions nicegui/element_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ def __init__(self, *,
self._kind = kind
self._markers = marker.split() if isinstance(marker, str) else marker
self._contents = [content] if isinstance(content, str) else content

self._within_kinds: List[Type[Element]] = []
self._within_markers: List[str] = []
self._within_instances: List[Element] = []
self._within_markers: List[str] = []

self._not_within_kinds: List[Type[Element]] = []
self._not_within_markers: List[str] = []
self._not_within_instances: List[Element] = []
self._not_within_markers: List[str] = []

self._exclude_kinds: List[Type[Element]] = []
self._exclude_markers: List[str] = []
self._exclude_content: List[str] = []

self._scope = context.slot.parent if local_scope else context.client.layout

def __iter__(self) -> Iterator[T]:
Expand Down Expand Up @@ -89,9 +93,9 @@ def _iterate(self, parent: Element, *, visited: Optional[List[Element]] = None)
(self._kind is None or isinstance(element, self._kind)) and
(not self._markers or all(m in element._markers for m in self._markers)) and
(not self._contents or all(c in content for c in self._contents)) and
(not self._exclude_kinds or not any(isinstance(element, kinds) for kinds in self._exclude_kinds)) and
(not self._exclude_kinds or not isinstance(element, tuple(self._exclude_kinds))) and
(not self._exclude_markers or not any(m in element._markers for m in self._exclude_markers)) and
(not self._exclude_content or (hasattr(element, 'text') and not any(text in element.text for text in self._exclude_content))) and
(not self._exclude_content or not any(text in getattr(element, 'text', '') for text in self._exclude_content)) and
(not self._within_instances or any(element in instance for instance in self._within_instances))
):
if (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_element_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async def test_typing(user: User):

await user.open('/')
# NOTE we have not yet found a way to test the typing suggestions automatically
# to test, hover over the variable and verify that your IDE inferres the correct type
# to test, hover over the variable and verify that your IDE infers the correct type
_ = ElementFilter(kind=ui.button) # ElementFilter[ui.button]
_ = ElementFilter(kind=ui.label) # ElementFilter[ui.label]
_ = ElementFilter() # ElementFilter[Element]

0 comments on commit 23ab58c

Please sign in to comment.