First note that in the old code, the entire list is evaluated before the any() is called. Changing this code solves two issues. 1) if there is an error in one of these conditions, then the entire function won't error out immediately but may hit a True condition and exit early. 2) Most of these conditions are inexpensive lookups, but some, like 'any_raspberry_pi' perform lots of logic including an IO lookup

This commit is contained in:
CamDavidsonPilon 2021-12-06 17:36:27 -05:00
parent f81d412e88
commit 1b733c0c3b

View file

@ -618,32 +618,32 @@ class Board:
@property
def any_embedded_linux(self):
"""Check whether the current board is any embedded Linux device."""
return any(
[
self.any_raspberry_pi_40_pin,
self.any_raspberry_pi,
self.any_beaglebone,
self.any_orange_pi,
self.any_nanopi,
self.any_giant_board,
self.any_jetson_board,
self.any_coral_board,
self.any_odroid_40_pin,
self.any_96boards,
self.any_sifive_board,
self.any_onion_omega_board,
self.any_pine64_board,
self.any_pynq_board,
self.any_rock_pi_board,
self.any_clockwork_pi_board,
self.any_udoo_board,
self.any_asus_tinker_board,
self.any_stm32mp1,
self.any_lubancat,
self.any_bananapi,
self.any_maaxboard,
]
)
def lazily_generate_conditions():
yield self.any_raspberry_pi_40_pi
yield self.any_raspberry_pi
yield self.any_beaglebone
yield self.any_orange_pi
yield self.any_nanopi
yield self.any_giant_board
yield self.any_jetson_board
yield self.any_coral_board
yield self.any_odroid_40_pin
yield self.any_96boards
yield self.any_sifive_board
yield self.any_onion_omega_board
yield self.any_pine64_board
yield self.any_pynq_board
yield self.any_rock_pi_board
yield self.any_clockwork_pi_board
yield self.any_udoo_board
yield self.any_asus_tinker_board
yield self.any_stm32mp1
yield self.any_lubancat
yield self.any_bananapi
yield self.any_maaxboard
return any(condition for condition in lazily_generate_conditions())
@property
def ftdi_ft232h(self):