refactor: read Settings() once in display.py orientation/init paths
What changed, and why it matters
This is a straightforward internal code cleanup: it reads device settings once and reuses the result instead of reading them multiple times. The commit message and diff show no change in behavior, no bug fix, and no security relevance.
No security action needed; treat as a normal performance/readability refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors display.py so that Settings() is instantiated once per call path and stored in a local variable (display_settings / hardware) rather than being accessed repeatedly via attribute chains. The logic for lcd.init, to_landscape, and to_portrait is identical; only the number of Settings() lookups is reduced. No functional or security change is present in the diff.
Changed components
src/krux/display.pyInspect captured patch +12 / −13
diff --git a/src/krux/display.py b/src/krux/display.py
index fac23bb..4f458f2 100644
--- a/src/krux/display.py
+++ b/src/krux/display.py
@@ -167,9 +167,10 @@ class Display:
offset_h0=80,
)
elif kboard.is_amigo:
- lcd_type = Settings().hardware.display.lcd_type
- invert = Settings().hardware.display.inverted_colors
- bgr_to_rgb = Settings().hardware.display.bgr_colors
+ display_settings = Settings().hardware.display
+ lcd_type = display_settings.lcd_type
+ invert = display_settings.inverted_colors
+ bgr_to_rgb = display_settings.bgr_colors
lcd.init(invert=invert, lcd_type=lcd_type)
lcd.mirror(True)
lcd.bgr_to_rgb(bgr_to_rgb)
@@ -243,23 +244,21 @@ class Display:
def to_landscape(self):
"""Changes the rotation of the display to landscape"""
if self.portrait:
- lcd.rotation(
- (LANDSCAPE + 2) % 4
- if hasattr(Settings().hardware, "display")
- and getattr(Settings().hardware.display, "flipped_orientation", False)
- else LANDSCAPE
+ hardware = Settings().hardware
+ flipped = hasattr(hardware, "display") and getattr(
+ hardware.display, "flipped_orientation", False
)
+ lcd.rotation((LANDSCAPE + 2) % 4 if flipped else LANDSCAPE)
self.portrait = False
def to_portrait(self):
"""Changes the rotation of the display to portrait"""
if not self.portrait:
- lcd.rotation(
- (PORTRAIT + 2) % 4
- if hasattr(Settings().hardware, "display")
- and getattr(Settings().hardware.display, "flipped_orientation", False)
- else PORTRAIT
+ hardware = Settings().hardware
+ flipped = hasattr(hardware, "display") and getattr(
+ hardware.display, "flipped_orientation", False
)
+ lcd.rotation((PORTRAIT + 2) % 4 if flipped else PORTRAIT)
self.portrait = True
def _usable_pixels_in_line(self):
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.