# HG changeset patch
# User Antonio Muci <
a....@inwind.it>
# Date 1742332955 -3600
# Tue Mar 18 22:22:35 2025 +0100
# Branch stable
# Node ID 46987ac2df43ba55ad335690480c1c60e754d2ce
# Parent ae24d8b47e5dde57abecb97e33bf431a9688bdac
blockmatcher: add type hints to four functions in BlockList. Fix a type error
This commit adds type hints to the four functions that are involved in a Qt6
crash detailed in #6023. In the process it becomes evident a type mismatch that
always existed. The commit also fixes that one.
This is the mismatch: scrollToPos() called setValue() with a float value.
setValue() in turn emitted the pyqtSignal(int) valueChanged, but passing the
float value instead.
This was fine in Qt5, but would break in Qt6.
This commit puts in place the type hints and rounds to int "value" as a
preventive measure, that stays compatible with Qt5, and would not break under
Qt6.
The final fix for the crash will be put in place in the next commit.
diff --git a/tortoisehg/hgqt/blockmatcher.py b/tortoisehg/hgqt/blockmatcher.py
--- a/tortoisehg/hgqt/blockmatcher.py
+++ b/tortoisehg/hgqt/blockmatcher.py
@@ -92,7 +92,7 @@ class BlockList(QWidget):
self.update()
self.rangeChanged.emit(self._minimum, self._maximum)
- def setValue(self, val):
+ def setValue(self, val: int) -> None:
if val != self._value:
self._value = val
self.update()
@@ -141,21 +141,21 @@ class BlockList(QWidget):
p.setBrush(self._vrectcolor)
p.drawRect(0, int(self._value * sy), w, int(self._pagestep * sy))
- def scrollToPos(self, y):
+ def scrollToPos(self, y: int) -> None:
# Scroll to the position which specified by Y coodinate.
if not isinstance(self._sbar, QScrollBar):
return
ratio = float(y) / self.height()
minimum, maximum, step = self._minimum, self._maximum, self._pagestep
- value = minimum + (maximum + step - minimum) * ratio - (step * 0.5)
+ value = int(minimum + (maximum + step - minimum) * ratio - (step * 0.5))
value = min(maximum, max(minimum, value)) # round to valid range.
self.setValue(value)
- def mousePressEvent(self, event):
+ def mousePressEvent(self, event: QMouseEvent) -> None:
super().mousePressEvent(event)
self.scrollToPos(event.y())
- def mouseMoveEvent(self, event):
+ def mouseMoveEvent(self, event: QMouseEvent) -> None:
super().mouseMoveEvent(event)
self.scrollToPos(event.y())