Skip to content

Commit c5bdb01

Browse files
otherJL0tony
authored andcommitted
Refactor common where method
1 parent c522878 commit c5bdb01

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
@@ -336,19 +336,20 @@ def where(self, attrs, first=False):
336336
"""
337337

338338
# from https://github.com/serkanyersen/underscore.py
339-
def by(val, *args):
340-
for key, value in attrs.items():
339+
def by(val) -> bool:
340+
for key in attrs.keys():
341341
try:
342342
if attrs[key] != val[key]:
343343
return False
344344
except KeyError:
345345
return False
346-
return True
346+
return True
347347

348+
# TODO add type hint
349+
target_children = list(filter(by, self.children))
348350
if first:
349-
return list(filter(by, self.children))[0]
350-
else:
351-
return list(filter(by, self.children))
351+
return target_children[0]
352+
return return target_children
352353

353354
def get_by_id(self, id):
354355
"""

0 commit comments

Comments
 (0)