[PATCH 2 of 4] typing: add typehints around events calling `.pos()`

9 views
Skip to first unread message

Matt Harbison

unread,
Dec 2, 2023, 8:46:35 PM12/2/23
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1701550287 18000
# Sat Dec 02 15:51:27 2023 -0500
# Branch stable
# Node ID 77b25021b7687d866bf9854ecb5b64ba90c25ffb
# Parent 9612bce5298f15bec3fefacc81e7aa1ac6861ca0
# EXP-Topic qt6-fixes
typing: add typehints around events calling `.pos()`

The Qt5 -> Qt6 transition cut the number of `.pos()` functions in QtGui from 11
to 4. Only the QMouseEvent, QMoveEvent, QContextMenuEvent, and QHelpEvent
remain unchanged in the type hints. In an effort to see if there were any other
instances of rename problems like the previous commit, I grepped for `pos\(\)`,
and placed typehints where it was already correct, in cse they get changed in
the future. In the end, this covered all instances of that pattern that were Qt
function calls.

diff --git a/tortoisehg/hgqt/fileview.py b/tortoisehg/hgqt/fileview.py
--- a/tortoisehg/hgqt/fileview.py
+++ b/tortoisehg/hgqt/fileview.py
@@ -11,6 +11,10 @@
import os
import re

+from typing import (
+ cast,
+)
+
from . import qsci as Qsci
from .qtcore import (
QElapsedTimer,
@@ -33,6 +37,7 @@
QInputDialog,
QKeySequence,
QLabel,
+ QMouseEvent,
QPalette,
QShortcut,
QStyle,
@@ -1002,7 +1007,7 @@
self._sci.markerDeleteAll()
self._cmdsession.abort()

- def eventFilter(self, watched, event):
+ def eventFilter(self, watched: QObject, event: QEvent) -> bool:
# Python wrapper is deleted immediately before QEvent.Destroy
try:
sciviewport = self._sci.viewport()
@@ -1010,7 +1015,7 @@
sciviewport = None
if watched is sciviewport:
if event.type() == QEvent.Type.MouseMove:
- line = self._sci.lineNearPoint(event.pos())
+ line = self._sci.lineNearPoint(cast(QMouseEvent, event).pos())
self._emitRevisionHintAtLine(line)
return False
return super(_AnnotateViewControl, self).eventFilter(watched, event)
diff --git a/tortoisehg/hgqt/reporegistry.py b/tortoisehg/hgqt/reporegistry.py
--- a/tortoisehg/hgqt/reporegistry.py
+++ b/tortoisehg/hgqt/reporegistry.py
@@ -36,6 +36,7 @@
QFrame,
QMenu,
QMessageBox,
+ QMouseEvent,
QTreeView,
QVBoxLayout,
)
@@ -192,7 +193,7 @@
return
super(RepoTreeView, self).keyPressEvent(event)

- def mouseMoveEvent(self, event):
+ def mouseMoveEvent(self, event: QMouseEvent) -> None:
self.msg = ''
pos = event.pos()
idx = self.indexAt(pos)
@@ -211,7 +212,7 @@
if self.msg != '':
self.showMessage.emit('')

- def mouseDoubleClickEvent(self, event):
+ def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
index = self.indexAt(event.pos())
if index.isValid() and index.internalPointer().isRepo():
self.openRequested.emit(index)
diff --git a/tortoisehg/hgqt/repotab.py b/tortoisehg/hgqt/repotab.py
--- a/tortoisehg/hgqt/repotab.py
+++ b/tortoisehg/hgqt/repotab.py
@@ -24,6 +24,7 @@
QActionGroup,
QKeySequence,
QMenu,
+ QMouseEvent,
QShortcut,
QStackedLayout,
QTabBar,
@@ -46,7 +47,7 @@

class _TabBar(QTabBar):

- def mouseReleaseEvent(self, event):
+ def mouseReleaseEvent(self, event: QMouseEvent) -> None:
if event.button() == Qt.MouseButton.MiddleButton:
self.tabCloseRequested.emit(self.tabAt(event.pos()))
super(_TabBar, self).mouseReleaseEvent(event)
diff --git a/tortoisehg/hgqt/repoview.py b/tortoisehg/hgqt/repoview.py
--- a/tortoisehg/hgqt/repoview.py
+++ b/tortoisehg/hgqt/repoview.py
@@ -48,6 +48,7 @@
QListWidget,
QListWidgetItem,
QMenu,
+ QMouseEvent,
QPainter,
QPainterPath,
QPen,
@@ -137,7 +138,7 @@
def repo(self):
return self._repoagent.rawRepo()

- def mousePressEvent(self, event):
+ def mousePressEvent(self, event: QMouseEvent) -> None:
index = self.indexAt(event.pos())
if not index.isValid():
return

Matt Harbison

unread,
Dec 2, 2023, 8:46:35 PM12/2/23
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1701548552 18000
# Sat Dec 02 15:22:32 2023 -0500
# Branch stable
# Node ID 9612bce5298f15bec3fefacc81e7aa1ac6861ca0
# Parent d524cb1fcbb04840db6293f050e59ca67672b4b9
# EXP-Topic qt6-fixes
reporegistry: fix a Qt6 crash when reordering repositories (fixes #5959)

diff --git a/tortoisehg/hgqt/qtlib.py b/tortoisehg/hgqt/qtlib.py
--- a/tortoisehg/hgqt/qtlib.py
+++ b/tortoisehg/hgqt/qtlib.py
@@ -25,6 +25,7 @@
QEvent,
QFile,
QObject,
+ QPoint,
QProcess,
QSettings,
QSignalMapper,
@@ -45,6 +46,7 @@
QColor,
QDesktopServices,
QDialog,
+ QDropEvent,
QFont,
QFrame,
QHBoxLayout,
@@ -1658,3 +1660,11 @@
# pytype: enable=attribute-error

return cast(Qt.CheckState, value)
+
+
+def qDropEventPosition(event: QDropEvent) -> QPoint:
+ """Retrieve QPoint position for the drop event"""
+ if QT_VERSION >= 0x060000:
+ return event.position().toPoint() # pytype: disable=attribute-error
+ else:
+ return event.pos() # pytype: disable=attribute-error
diff --git a/tortoisehg/hgqt/reporegistry.py b/tortoisehg/hgqt/reporegistry.py
--- a/tortoisehg/hgqt/reporegistry.py
+++ b/tortoisehg/hgqt/reporegistry.py
@@ -30,6 +30,7 @@
QAction,
QApplication,
QDockWidget,
+ QDropEvent,
QFileDialog,
QFontMetrics,
QFrame,
@@ -108,8 +109,8 @@
self.setState(QAbstractItemView.State.DraggingState)
break

- def dropLocation(self, event):
- index = self.indexAt(event.pos())
+ def dropLocation(self, event: QDropEvent):
+ index = self.indexAt(qtlib.qDropEventPosition(event))

# Determine where the item was dropped.
target = index.internalPointer()
@@ -146,7 +147,7 @@

super(RepoTreeView, self).startDrag(supportedActions)

- def dropEvent(self, event):
+ def dropEvent(self, event: QDropEvent):
data = event.mimeData()
index, group, row = self.dropLocation(event)


Matt Harbison

unread,
Dec 2, 2023, 8:46:37 PM12/2/23
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1701565205 18000
# Sat Dec 02 20:00:05 2023 -0500
# Branch stable
# Node ID f6f17e9c82000d4a771987bcf026340d6f3ff9c8
# Parent d4f302077448e99bdf93a84e196fa1f8446d4282
# EXP-Topic qt6-fixes
contrib: force the generated CI config file to use \n on Windows

This copies the dispatch.initstdio() function from Mercurial. Setting
`line_break='\n'` on the dumper wasn't enough.

diff --git a/contrib/generate_gitlab_ci_yml.py b/contrib/generate_gitlab_ci_yml.py
--- a/contrib/generate_gitlab_ci_yml.py
+++ b/contrib/generate_gitlab_ci_yml.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

+import io
import json
import re
import sys
@@ -113,10 +114,54 @@
return {**tests, **pytype}


+def initstdio():
+ # stdio streams on Python 3 are io.TextIOWrapper instances proxying another
+ # buffer. These streams will normalize \n to \r\n by default.
+
+ if sys.stdout is not None:
+ # write_through is new in Python 3.7.
+ kwargs = {
+ "newline": "\n",
+ "line_buffering": sys.stdout.line_buffering,
+ }
+ if hasattr(sys.stdout, "write_through"):
+ # pytype: disable=attribute-error
+ kwargs["write_through"] = sys.stdout.write_through
+ # pytype: enable=attribute-error
+ sys.stdout = io.TextIOWrapper(
+ sys.stdout.buffer, sys.stdout.encoding, sys.stdout.errors, **kwargs
+ )
+
+ if sys.stderr is not None:
+ kwargs = {
+ "newline": "\n",
+ "line_buffering": sys.stderr.line_buffering,
+ }
+ if hasattr(sys.stderr, "write_through"):
+ # pytype: disable=attribute-error
+ kwargs["write_through"] = sys.stderr.write_through
+ # pytype: enable=attribute-error
+ sys.stderr = io.TextIOWrapper(
+ sys.stderr.buffer, sys.stderr.encoding, sys.stderr.errors, **kwargs
+ )
+
+ if sys.stdin is not None:
+ # No write_through on read-only stream.
+ sys.stdin = io.TextIOWrapper(
+ sys.stdin.buffer,
+ sys.stdin.encoding,
+ sys.stdin.errors,
+ # None is universal newlines mode.
+ newline=None,
+ line_buffering=sys.stdin.line_buffering,
+ )
+
+
if __name__ == '__main__':
+ initstdio()
toplevel = gen_gitlab_ci_yml()
sys.stdout.write(
"# This file was generated by contrib/generate_gitlab_ci_yml.py.\n\n"
)
- yaml.dump(toplevel, sys.stdout, sort_keys=False)
+ yaml.dump(toplevel, sys.stdout, line_break='\n', sort_keys=False)
sys.stdout.flush()

Matt Harbison

unread,
Dec 2, 2023, 8:46:37 PM12/2/23
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1701563890 18000
# Sat Dec 02 19:38:10 2023 -0500
# Branch stable
# Node ID d4f302077448e99bdf93a84e196fa1f8446d4282
# Parent 77b25021b7687d866bf9854ecb5b64ba90c25ffb
# EXP-Topic qt6-fixes
ci: regenerate to add test cases for hg 6.4 - hg 6.6

At some point, we should probably pare this down (maybe keep the earliest
`testedwith`, and the latest 3 or 4?). But the pytype tests are the long pole
by far, so I'm not worried about it yet.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -70,6 +70,48 @@
- make local PYTHON=python3 HGPATH=/ci/repos/mercurial
- xvfb-run make tests PYTHON=python3 HGPATH=/ci/repos/mercurial
allow_failure: false
+tests-hg-6.4:
+ image: registry.heptapod.net/mercurial/ci-images/py3-hgext3rd
+ script:
+ - apt-get update
+ - apt-get -y install python3-pyqt5 python3-pyqt5.qsci xvfb
+ - pip3 install --user nose mock
+ - hg -R /ci/repos/mercurial pull
+ - hg -R /ci/repos/mercurial update 'tag("re:\A6\.4")'
+ - hg -R /ci/repos/mercurial summary
+ - make -C /ci/repos/mercurial local PYTHON=python3
+ - /ci/repos/mercurial/hg version --debug
+ - make local PYTHON=python3 HGPATH=/ci/repos/mercurial
+ - xvfb-run make tests PYTHON=python3 HGPATH=/ci/repos/mercurial
+ allow_failure: false
+tests-hg-6.5:
+ image: registry.heptapod.net/mercurial/ci-images/py3-hgext3rd
+ script:
+ - apt-get update
+ - apt-get -y install python3-pyqt5 python3-pyqt5.qsci xvfb
+ - pip3 install --user nose mock
+ - hg -R /ci/repos/mercurial pull
+ - hg -R /ci/repos/mercurial update 'tag("re:\A6\.5")'
+ - hg -R /ci/repos/mercurial summary
+ - make -C /ci/repos/mercurial local PYTHON=python3
+ - /ci/repos/mercurial/hg version --debug
+ - make local PYTHON=python3 HGPATH=/ci/repos/mercurial
+ - xvfb-run make tests PYTHON=python3 HGPATH=/ci/repos/mercurial
+ allow_failure: false
+tests-hg-6.6:
+ image: registry.heptapod.net/mercurial/ci-images/py3-hgext3rd
+ script:
+ - apt-get update
+ - apt-get -y install python3-pyqt5 python3-pyqt5.qsci xvfb
+ - pip3 install --user nose mock
+ - hg -R /ci/repos/mercurial pull
+ - hg -R /ci/repos/mercurial update 'tag("re:\A6\.6")'
+ - hg -R /ci/repos/mercurial summary
+ - make -C /ci/repos/mercurial local PYTHON=python3
+ - /ci/repos/mercurial/hg version --debug
+ - make local PYTHON=python3 HGPATH=/ci/repos/mercurial
+ - xvfb-run make tests PYTHON=python3 HGPATH=/ci/repos/mercurial
+ allow_failure: false
tests-hg-stable:
image: registry.heptapod.net/mercurial/ci-images/py3-hgext3rd
script:

Yuya Nishihara

unread,
Dec 2, 2023, 11:02:29 PM12/2/23
to Matt Harbison, thg...@googlegroups.com
On Sat, 02 Dec 2023 20:46:29 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_h...@yahoo.com>
> # Date 1701548552 18000
> # Sat Dec 02 15:22:32 2023 -0500
> # Branch stable
> # Node ID 9612bce5298f15bec3fefacc81e7aa1ac6861ca0
> # Parent d524cb1fcbb04840db6293f050e59ca67672b4b9
> # EXP-Topic qt6-fixes
> reporegistry: fix a Qt6 crash when reordering repositories (fixes #5959)

Queued for stable, thanks.
Reply all
Reply to author
Forward
0 new messages