Skip to content

Commit 4d9b6c2

Browse files
committed
Refactor common where method
1 parent 061b9e7 commit 4d9b6c2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

libtmux/common.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,20 @@ def where(self, attrs, first=False):
332332
"""
333333

334334
# from https://github.com/serkanyersen/underscore.py
335-
def by(val, *args):
336-
for key, value in attrs.items():
335+
def by(val) -> bool:
336+
for key in attrs.keys():
337337
try:
338338
if attrs[key] != val[key]:
339339
return False
340340
except KeyError:
341341
return False
342-
return True
342+
return True
343343

344+
# TODO add type hint
345+
target_children = list(filter(by, self.children))
344346
if first:
345-
return list(filter(by, self.children))[0]
346-
else:
347-
return list(filter(by, self.children))
347+
return target_children[0]
348+
return return target_children
348349

349350
def get_by_id(self, id):
350351
"""

0 commit comments

Comments
 (0)