Skip to content

Commit 1b733c0

Browse files
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
1 parent f81d412 commit 1b733c0

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

adafruit_platformdetect/board.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -618,32 +618,32 @@ def any_maaxboard(self):
618618
@property
619619
def any_embedded_linux(self):
620620
"""Check whether the current board is any embedded Linux device."""
621-
return any(
622-
[
623-
self.any_raspberry_pi_40_pin,
624-
self.any_raspberry_pi,
625-
self.any_beaglebone,
626-
self.any_orange_pi,
627-
self.any_nanopi,
628-
self.any_giant_board,
629-
self.any_jetson_board,
630-
self.any_coral_board,
631-
self.any_odroid_40_pin,
632-
self.any_96boards,
633-
self.any_sifive_board,
634-
self.any_onion_omega_board,
635-
self.any_pine64_board,
636-
self.any_pynq_board,
637-
self.any_rock_pi_board,
638-
self.any_clockwork_pi_board,
639-
self.any_udoo_board,
640-
self.any_asus_tinker_board,
641-
self.any_stm32mp1,
642-
self.any_lubancat,
643-
self.any_bananapi,
644-
self.any_maaxboard,
645-
]
646-
)
621+
622+
def lazily_generate_conditions():
623+
yield self.any_raspberry_pi_40_pi
624+
yield self.any_raspberry_pi
625+
yield self.any_beaglebone
626+
yield self.any_orange_pi
627+
yield self.any_nanopi
628+
yield self.any_giant_board
629+
yield self.any_jetson_board
630+
yield self.any_coral_board
631+
yield self.any_odroid_40_pin
632+
yield self.any_96boards
633+
yield self.any_sifive_board
634+
yield self.any_onion_omega_board
635+
yield self.any_pine64_board
636+
yield self.any_pynq_board
637+
yield self.any_rock_pi_board
638+
yield self.any_clockwork_pi_board
639+
yield self.any_udoo_board
640+
yield self.any_asus_tinker_board
641+
yield self.any_stm32mp1
642+
yield self.any_lubancat
643+
yield self.any_bananapi
644+
yield self.any_maaxboard
645+
646+
return any(condition for condition in lazily_generate_conditions())
647647

648648
@property
649649
def ftdi_ft232h(self):

0 commit comments

Comments
 (0)