refactor: dedupe flipped-orientation check in touch.py via is_flipped_orientation
What changed, and why it matters
This commit is a simple code cleanup: it replaces two copies of the same display-orientation check with a single shared helper method. There is no security-relevant change in behavior; the logic before and after is functionally identical.
No security action needed. Treat as ordinary code-quality/maintenance review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors src/krux/touch.py to call Settings().is_flipped_orientation() instead of inline hasattr/getattr checks against Settings().hardware.display.flipped_orientation. The test fixture is updated to mock the new helper. This is a pure deduplication refactor with no functional or security impact.
Changed components
src/krux/touch.pytests/test_touch.pyInspect captured patch +4 / −8
diff --git a/src/krux/touch.py b/src/krux/touch.py
index 3bdece8..5cb1721 100644
--- a/src/krux/touch.py
+++ b/src/krux/touch.py
@@ -93,9 +93,7 @@ class Touch:
def valid_position(self, data):
"""Checks if touch position is within buttons area"""
- if hasattr(Settings().hardware, "display") and getattr(
- Settings().hardware.display, "flipped_orientation", False
- ):
+ if Settings().is_flipped_orientation():
data = (self.height - data[0], self.width - data[1])
if self.x_regions and data[0] < self.x_regions[0]:
@@ -189,9 +187,7 @@ class Touch:
def _store_points(self, data):
"""Store pressed points and calculare an average pressed point"""
- if hasattr(Settings().hardware, "display") and getattr(
- Settings().hardware.display, "flipped_orientation", False
- ):
+ if Settings().is_flipped_orientation():
new_y = max(0, self.height - data[0])
new_y = min(new_y, self.height - 1)
new_x = max(0, self.width - data[1])
diff --git a/tests/test_touch.py b/tests/test_touch.py
index 3f03ff7..07388cf 100644
--- a/tests/test_touch.py
+++ b/tests/test_touch.py
@@ -7,8 +7,8 @@ def mock_settings(mocker):
"""Mock Settings to avoid dependency on hardware config"""
mock_settings_obj = mocker.MagicMock()
mock_settings_obj.hardware.touch.threshold = 40
- # Ensure hardware doesn't have display attribute to avoid coordinate flipping
- del mock_settings_obj.hardware.display
+ # Default to no coordinate flipping
+ mock_settings_obj.is_flipped_orientation.return_value = False
mock_settings_class = mocker.patch("krux.touch.Settings")
mock_settings_class.return_value = mock_settings_obj
return mock_settings_obj
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.