lint: Add misc check for QTimer initialization

Since we added some sanity checking in usertypes.Timer() around
QTBUG-124496 it would be convenient if there was a reminder for future
timer users to use our Timer object instead. Here's one!

It's looking for QTimer initialisations, we are still allowing
QTimer.singleShot(), although that probably can hit the same issue.

It uses an end-of-line anchor in the regex so you can put a comment (any
comment) on the end of the line to ignore the check.
This commit is contained in:
toofar 2024-05-11 12:47:51 +12:00
parent 38abfdb8a0
commit c5fa5a0dc9
2 changed files with 6 additions and 2 deletions

View File

@ -274,6 +274,10 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]:
re.compile(r'qutebrowser is free software: you can redistribute'),
"use 'SPDX-License-Identifier: GPL-3.0-or-later' instead",
),
(
re.compile(r'QTimer\(.*\)$'),
"use usertypes.Timer() instead of a plain QTimer",
),
]
# Files which should be ignored, e.g. because they come from another

View File

@ -1118,13 +1118,13 @@ class TestQObjRepr:
assert qtutils.qobj_repr(obj) == expected
def test_class_name(self):
obj = QTimer()
obj = QTimer() # misc: ignore
hidden = sip.cast(obj, QObject)
expected = f"<{self._py_repr(hidden)}, className='QTimer'>"
assert qtutils.qobj_repr(hidden) == expected
def test_both(self):
obj = QTimer()
obj = QTimer() # misc: ignore
obj.setObjectName("Pomodoro")
hidden = sip.cast(obj, QObject)
expected = f"<{self._py_repr(hidden)}, objectName='Pomodoro', className='QTimer'>"