Skip to content

Commit

Permalink
refactor: replace lambda with readable equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
smlng committed Apr 19, 2021
1 parent 55386e1 commit 2c55d99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cayennelpp/lpp_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ def size(self):

def get_by_type(self, type_):
"""Return sub list of data with items matching given type."""
return list(filter(lambda t: (int(t.type) == type_), self.data))
return [d for d in self.data if int(d.type) == type_]

def get_by_name(self, name):
"""Return sub list of data with items matching given name."""
return list(filter(lambda t: (str(t.type).lower() == name.lower()), self.data))
name = name.strip().lower()
return [d for d in self.data if str(d.type).lower().startswith(name)]

def add_by_type(self, type_, channel, value_tuple):
"""Generic helper to add LppDate to this LppFrame."""
Expand Down
1 change: 1 addition & 0 deletions cayennelpp/tests/test_lpp_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def test_get_by_name(frame_hlt):
b_list = frame_hlt.get_by_name("Barometer")
assert len(b_list) == 0


def test_get_by_type_invalid(frame_hlt):
p_list = frame_hlt.get_by_type(102)
assert len(p_list) == 0
Expand Down

0 comments on commit 2c55d99

Please sign in to comment.