From 5871c959e22f9399430195ba2a1d41b9dc16c662 Mon Sep 17 00:00:00 2001 From: Dawn Date: Fri, 14 Aug 2026 08:52:01 +0200 Subject: [PATCH] fix: clear basedpyright diff violations Rename NumberLineEdit.validator to range_validator: the instance attr shadowed QLineEdit.validator() and broke type checking at call sites. Annotate the smargon _move_axes dict and cast the stand-in self in the prediction subscriber test. Co-Authored-By: Claude Fable 5 --- src/aare/gui/panels/smargon_panel.py | 2 +- src/aare/gui/widgets/motor_move_group.py | 4 ++-- src/aare/gui/widgets/number_line_edit.py | 16 +++++++++------- tests/unit/gui/test_prediction_subscriber.py | 7 +++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/aare/gui/panels/smargon_panel.py b/src/aare/gui/panels/smargon_panel.py index 3b1ae2a4..462030e0 100644 --- a/src/aare/gui/panels/smargon_panel.py +++ b/src/aare/gui/panels/smargon_panel.py @@ -109,7 +109,7 @@ class SmargonPanel(QWidget): self.smargon.emit(SmargonCoordinate(sh_mm=Coordinate(x=0, y=0, z=18), phi_deg=0, chi_deg=0)) @Slot(dict) - def _move_axes(self, targets: dict): + def _move_axes(self, targets: dict[str, float]): # only the staged axes move — absent keys stay None (no motion) self.smargon.emit(SmargonCoordinate(chi_deg=targets.get("chi"), phi_deg=targets.get("phi"))) diff --git a/src/aare/gui/widgets/motor_move_group.py b/src/aare/gui/widgets/motor_move_group.py index f04fcb91..2013d110 100644 --- a/src/aare/gui/widgets/motor_move_group.py +++ b/src/aare/gui/widgets/motor_move_group.py @@ -72,7 +72,7 @@ class MotorMoveGroup(QObject): # incomplete entry ("", "-", "1e"): stay/become pending, no tips self._set_state(name, "pending") return - top = box.validator.top() + top = box.range_validator.top() if value > top: QToolTip.showText( box.mapToGlobal(QPoint(0, box.height())), @@ -96,7 +96,7 @@ class MotorMoveGroup(QObject): value = float(box.text()) except ValueError: break - bottom = box.validator.bottom() + bottom = box.range_validator.bottom() if value < bottom: QToolTip.showText( box.mapToGlobal(QPoint(0, box.height())), diff --git a/src/aare/gui/widgets/number_line_edit.py b/src/aare/gui/widgets/number_line_edit.py index 98f22441..3a0de0db 100644 --- a/src/aare/gui/widgets/number_line_edit.py +++ b/src/aare/gui/widgets/number_line_edit.py @@ -17,12 +17,14 @@ class NumberLineEdit(QLineEdit): self._read_only: bool = False self._is_valid: bool = True - # Use a QDoubleValidator to only allow valid floating point numbers - self.validator = QDoubleValidator() - self.validator.setNotation(QDoubleValidator.Notation.StandardNotation) + # Use a QDoubleValidator to only allow valid floating point numbers. + # Named range_validator: plain "validator" would shadow + # QLineEdit.validator() and break type checking at call sites. + self.range_validator = QDoubleValidator() + self.range_validator.setNotation(QDoubleValidator.Notation.StandardNotation) self.decimal_count = decimals - self.validator.setRange(min_val, max_val, self.decimal_count) - self.setValidator(self.validator) + self.range_validator.setRange(min_val, max_val, self.decimal_count) + self.setValidator(self.range_validator) self.setAlignment(Qt.AlignmentFlag.AlignRight) self.setToolTip( f"Minimum: {self.to_string(min_val):s}\nMaximum: {self.to_string(max_val):s}" @@ -80,13 +82,13 @@ class NumberLineEdit(QLineEdit): @Slot(float, float) def update_limits(self, min_val: float, max_val: float): - self.validator.setRange(min_val, max_val, self.decimal_count) + self.range_validator.setRange(min_val, max_val, self.decimal_count) self.setToolTip( f"Minimum: {self.to_string(min_val):s}\nMaximum: {self.to_string(max_val):s}" ) def validate(self, text) -> bool: - return self.validator.validate(str(text), 0)[0] == QDoubleValidator.State.Acceptable + return self.range_validator.validate(str(text), 0)[0] == QDoubleValidator.State.Acceptable def setReadOnly(self, ro: bool): # Colors follow via the QSS :read-only pseudo-class (updates without diff --git a/tests/unit/gui/test_prediction_subscriber.py b/tests/unit/gui/test_prediction_subscriber.py index 6617ba55..c57552fb 100644 --- a/tests/unit/gui/test_prediction_subscriber.py +++ b/tests/unit/gui/test_prediction_subscriber.py @@ -2,13 +2,16 @@ byte) must be rejected without attempting utf-8 decode (previously raised UnicodeDecodeError on every frame).""" +from typing import cast + from aare.gui.threads.prediction_subscriber import PredictionSubscriber def _parse(part: bytes): # Called unbound: _try_parse_json touches no instance state, so no - # QThread/zmq construction is needed. - return PredictionSubscriber._try_parse_json(object(), part) + # QThread/zmq construction is needed. cast keeps basedpyright happy + # about the stand-in self. + return PredictionSubscriber._try_parse_json(cast(PredictionSubscriber, object()), part) def test_binary_jpeg_frame_is_not_json():