Skip to content

Commit 45548b1

Browse files
Fix some flake8 errors in tests/examples
As unearthed by the whitespace change. Pick-to: 6.8 Change-Id: I58c1a38c3c4a9c91719131d7950950ddf475872b Reviewed-by: Cristian Maureira-Fredes <[email protected]>
1 parent dc41b6a commit 45548b1

32 files changed

+52
-56
lines changed

sources/pyside6/doc/tutorials/datavisualize/datavisualize4/main_widget.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ def __init__(self, data):
2222
# QTableView Headers
2323
self.horizontal_header = self.table_view.horizontalHeader()
2424
self.vertical_header = self.table_view.verticalHeader()
25-
self.horizontal_header.setSectionResizeMode(
26-
QHeaderView.ResizeToContents
27-
)
28-
self.vertical_header.setSectionResizeMode(
29-
QHeaderView.ResizeToContents
30-
)
25+
self.horizontal_header.setSectionResizeMode(QHeaderView.ResizeToContents)
26+
self.vertical_header.setSectionResizeMode(QHeaderView.ResizeToContents)
3127
self.horizontal_header.setStretchLastSection(True)
3228

3329
# QWidget Layout
3430
self.main_layout = QHBoxLayout()
3531
size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
3632

37-
## Left layout
33+
# Left layout
3834
size.setHorizontalStretch(1)
3935
self.table_view.setSizePolicy(size)
4036
self.main_layout.addWidget(self.table_view)

sources/pyside6/doc/tutorials/datavisualize/datavisualize4/main_window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
33
from __future__ import annotations
44

5-
from PySide6.QtCore import Slot
65
from PySide6.QtGui import QAction, QKeySequence
76
from PySide6.QtWidgets import QMainWindow
87

@@ -16,7 +15,7 @@ def __init__(self, widget):
1615
self.menu = self.menuBar()
1716
self.file_menu = self.menu.addMenu("File")
1817

19-
## Exit QAction
18+
# Exit QAction
2019
exit_action = QAction("Exit", self)
2120
exit_action.setShortcut(QKeySequence.Quit)
2221
exit_action.triggered.connect(self.close)

sources/pyside6/doc/tutorials/datavisualize/datavisualize5/main_window.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
33
from __future__ import annotations
44

5-
from PySide6.QtCore import Slot
65
from PySide6.QtGui import QAction, QKeySequence
76
from PySide6.QtWidgets import QMainWindow
87

sources/pyside6/tests/QtCore/duck_punching_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def childEvent(self, event):
3333

3434

3535
class TestDuckPunchingOnQObjectInstance(UsesQApplication):
36-
'''Test case for duck punching new implementations of C++ virtual methods into object instances.'''
36+
'''Test case for duck punching new implementations of C++ virtual methods into
37+
object instances.'''
3738

3839
def setUp(self):
3940
# Acquire resources
@@ -65,7 +66,8 @@ def childEvent(obj, event):
6566
parent.childEvent = None
6667

6768
def testChildEventMonkeyPatchWithInheritance(self):
68-
# Test if the new childEvent injected on a QObject's extension class instance is called from C++
69+
'''Test if the new childEvent injected on a QObject's extension class
70+
instance is called from C++'''
6971
parent = Duck()
7072

7173
def childEvent(obj, event):

sources/pyside6/tests/QtCore/qbitarray_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def testQBitArrayIsIterable(self):
6262
# Tests if QBitArray class is iterable
6363
qbitarray_is_iterable = True
6464
try:
65-
bitarray = [bit for bit in self.qbitarray]
66-
except:
65+
bitarray = [bit for bit in self.qbitarray] # noqa F841
66+
except: # noqa: E722
6767
qbitarray_is_iterable = False
6868
self.assertTrue(qbitarray_is_iterable)
6969

@@ -81,8 +81,8 @@ def testQBitArrayOrBitwiseOperator(self):
8181
ored_qbitarray, ored_bool_list = None, None
8282
try:
8383
ored_qbitarray = self.qbitarray | self.other_qbitarray
84-
ored_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)]
85-
except:
84+
ored_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)] # noqa: E501
85+
except: # noqa: E722
8686
has_or_bitwise_operator = False
8787
self.assertTrue(has_or_bitwise_operator)
8888
self.assertEqual(bool_list_from_qbitarray(ored_qbitarray), ored_bool_list)
@@ -93,8 +93,8 @@ def testQBitArrayAndBitwiseOperator(self):
9393
anded_qbitarray, anded_bool_list = None, None
9494
try:
9595
anded_qbitarray = self.qbitarray | self.other_qbitarray
96-
anded_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)]
97-
except:
96+
anded_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)] # noqa: E501
97+
except: # noqa: E722
9898
has_and_bitwise_operator = False
9999
self.assertTrue(has_and_bitwise_operator)
100100
self.assertEqual(bool_list_from_qbitarray(anded_qbitarray), anded_bool_list)
@@ -105,8 +105,8 @@ def testQBitArrayXorBitwiseOperator(self):
105105
xored_qbitarray, xored_bool_list = None, None
106106
try:
107107
xored_qbitarray = self.qbitarray | self.other_qbitarray
108-
xored_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)]
109-
except:
108+
xored_bool_list = [b1 | b2 for b1, b2 in zip(self.qbitarray_values, self.other_qbitarray_values)] # noqa: E501
109+
except: # noqa: E722
110110
has_xor_bitwise_operator = False
111111
self.assertTrue(has_xor_bitwise_operator)
112112
self.assertEqual(bool_list_from_qbitarray(xored_qbitarray), xored_bool_list)

sources/pyside6/tests/QtCore/qbytearray_concatenation_operator_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def testConcatQByteArrayAndPythonString(self):
2929

3030
def testConcatPythonStringAndQByteArray(self):
3131
# Test concatenation of a Python bytes with a QByteArray, in this order
32-
concat_python_string_add_qbytearray_worked = True
3332
qba = QByteArray(bytes('foo', "UTF-8"))
3433
result = bytes('bar\x00', "UTF-8") + qba
3534
self.assertEqual(type(result), QByteArray)

sources/pyside6/tests/QtCore/qinstallmsghandler_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def testRet(self):
4646
ret = qInstallMessageHandler(None)
4747
self.assertEqual(ret, None)
4848
refcount = sys.getrefcount(handleruseless)
49-
retNone = qInstallMessageHandler(handleruseless)
49+
retNone = qInstallMessageHandler(handleruseless) # noqa: F841
5050
self.assertEqual(sys.getrefcount(handleruseless), refcount + 1)
5151
rethandler = qInstallMessageHandler(None)
5252
self.assertEqual(rethandler, handleruseless)
5353
del rethandler
5454
self.assertEqual(sys.getrefcount(handleruseless), refcount)
5555

5656
def testHandler(self):
57-
rethandler = qInstallMessageHandler(handler)
57+
rethandler = qInstallMessageHandler(handler) # noqa: F841
5858
if QLibraryInfo.isDebugBuild():
5959
qDebug("Test Debug")
6060
self.assertEqual(param[0], QtMsgType.QtDebugMsg)

sources/pyside6/tests/QtCore/qmodelindex_internalpointer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def tearDown(self):
3737
def testInternalPointer(self):
3838
# Test QAbstractListModel.createIndex and
3939
# QModelIndex.internalPointer with regular Python objects
40-
obj = QObject()
40+
obj = QObject() # noqa: F841
4141
idx = self.model.createIndex(0, 0, "Hello")
4242
i = idx.internalPointer()
4343
self.assertEqual(i, "Hello")
@@ -49,7 +49,7 @@ def testReferenceCounting(self):
4949
o = [1, 2, 3]
5050
o_refcnt = sys.getrefcount(o)
5151
idx = self.model.createIndex(0, 0, o)
52-
ptr = idx.internalPointer()
52+
ptr = idx.internalPointer() # noqa: F841
5353
self.assertEqual(sys.getrefcount(o), o_refcnt + 1)
5454

5555
def testIndexForDefaultDataArg(self):

sources/pyside6/tests/QtCore/qobject_objectproperty_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestBug378(unittest.TestCase):
3535
'''Test case for the bug #378'''
3636

3737
def testBug378(self):
38-
obj = ExtQObject()
38+
obj = ExtQObject() # noqa: F841
3939

4040

4141
if __name__ == '__main__':

sources/pyside6/tests/QtCore/qpoint_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
class QPointTest(unittest.TestCase):
2020

2121
def testQPointCtor(self):
22-
point = QPoint(QPoint(10, 20))
22+
point = QPoint(QPoint(10, 20)) # noqa: F841
2323

2424

2525
class QPointFTest(unittest.TestCase):
2626

2727
def testQPointFCtor(self):
28-
pointf = QPointF(QPoint(10, 20))
28+
pointf = QPointF(QPoint(10, 20)) # noqa: F841
2929

3030

3131
if __name__ == '__main__':

sources/pyside6/tests/QtCore/qresource_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
init_test_paths(False)
1515

1616
from PySide6.QtCore import QByteArray, QFile, QIODevice
17-
import resources_mc
17+
import resources_mc # noqa: F401
1818

1919

2020
class ResourcesUsage(unittest.TestCase):

sources/pyside6/tests/QtCore/unaryoperator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def testNegUnaryOperator(self):
4242
__neg__method_exists = True
4343
try:
4444
neg_qpoint = -self.qpoint
45-
except:
45+
except: # noqa: E722
4646
__neg__method_exists = False
4747

4848
self.assertTrue(__neg__method_exists)

sources/pyside6/tests/QtGui/qpen_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def testCtorWithCreatedEnums(self):
4141
style = Qt.PenStyle(0)
4242
cap = Qt.PenCapStyle(0)
4343
join = Qt.PenJoinStyle(0)
44-
pen = QPen(Qt.blue, width, style, cap, join)
44+
pen = QPen(Qt.blue, width, style, cap, join) # noqa: F841
4545

4646
def testSetPenWithPenStyleEnum(self):
4747
'''Calls QPainter.setPen with both enum and integer. Bug #511.'''

sources/pyside6/tests/QtGui/qpixmap_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def testQSizeConstructor(self):
2828
self.assertTrue(pixmap.size().height(), 20)
2929

3030
def testQStringConstructor(self):
31-
pixmap = QPixmap("Testing!")
31+
pixmap = QPixmap("Testing!") # noqa: F841
3232

3333
def testQPixmapLoadFromDataWithQFile(self):
3434
f = QFile(os.path.join(os.path.dirname(__file__), 'sample.png'))

sources/pyside6/tests/QtGui/qpixmapcache_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def testWithString(self):
3131
pm3 = QPixmap()
3232
ok = QPixmapCache.find('img', pm3)
3333
self.assertTrue(ok)
34-
b1 = QPixmapCache.find('img').toImage().bits()
35-
b2 = pm3.toImage().bits()
34+
b1 = QPixmapCache.find('img').toImage().bits() # noqa: F841
35+
b2 = pm3.toImage().bits() # noqa: F841
3636
self.assertEqual(QPixmapCache.find('img').toImage().bits(), pm3.toImage().bits())
3737

3838
def testWithKey(self):

sources/pyside6/tests/QtGui/qstandarditemmodel_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def testRefCount(self):
6767

6868
for r in range(3):
6969
my_row = model.takeRow(0)
70-
my_row = None
70+
my_row = None # noqa: F841
7171
for c in range(5):
7272
# only rest 1 reference
7373
self.assertEqual(sys.getrefcount(items[r][c]), 2)

sources/pyside6/tests/QtSvg/qsvgrenderer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class QSvgRendererTest(unittest.TestCase):
2121

2222
def testLoad(self):
2323
tigerPath = os.path.join(os.path.dirname(__file__), 'tiger.svg')
24-
app = QGuiApplication([])
24+
app = QGuiApplication([]) # noqa: F841
2525

2626
fromFile = QSvgRenderer(tigerPath)
2727
self.assertTrue(fromFile.isValid())

sources/pyside6/tests/QtSvgWidgets/qsvgwidget_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def testLoad(self):
2424
tigerPath = QDir.cleanPath(f"{directory}/../QtSvg/tiger.svg")
2525
self.assertTrue(QFileInfo.exists(tigerPath))
2626

27-
app = QApplication([])
27+
app = QApplication([]) # noqa: F841
2828
fromFile = QSvgWidget()
2929
fromFile.load(tigerPath)
3030
self.assertTrue(fromFile.renderer().isValid())

sources/pyside6/tests/QtUiTools/bug_360.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def testCase(self):
3838
loader = MyQUiLoader(w)
3939

4040
filePath = os.path.join(os.path.dirname(__file__), 'minimal.ui')
41-
ui = loader.load(filePath)
41+
ui = loader.load(filePath) # noqa: F841
4242

4343
self.assertEqual(len(loader._widgets), 1)
4444
self.assertEqual(type(loader._widgets[0]), QFrame)

sources/pyside6/tests/QtUiTools/uiloader_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def testLoadFile(self):
4141

4242
child = w.findChild(QWidget, "child_object")
4343
self.assertNotEqual(child, None)
44-
self.assertEqual(w.findChild(QWidget, "grandson_object"), child.findChild(QWidget, "grandson_object"))
44+
self.assertEqual(w.findChild(QWidget, "grandson_object"),
45+
child.findChild(QWidget, "grandson_object"))
4546

4647
def testLoadFileOverride(self):
4748
# PYSIDE-1070, override QUiLoader::createWidget() with parent=None crashes

sources/pyside6/tests/QtWidgets/bug_480.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup(self):
2828

2929
class LayoutTransferOwnerShip(unittest.TestCase):
3030
def testBug(self):
31-
app = QApplication([])
31+
app = QApplication([]) # noqa: F841
3232
w = BuggyWidget()
3333
w.setup()
3434
w.show()

sources/pyside6/tests/QtWidgets/bug_549.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class TestBug549(unittest.TestCase):
1818
def testBug(self):
19-
app = QApplication([])
19+
app = QApplication([]) # noqa: F841
2020
w = QGraphicsWidget()
2121
w.setContentsMargins(1, 2, 3, 4)
2222
self.assertEqual(w.getContentsMargins(), (1, 2, 3, 4))

sources/pyside6/tests/QtWidgets/bug_575.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class Bug575(unittest.TestCase):
2121
def testPropertyValues(self):
22-
app = QApplication(sys.argv)
22+
app = QApplication(sys.argv) # noqa: F841
2323
textEdit = QPlainTextEdit()
2424
textEdit.insertPlainText("PySide INdT")
2525
selection = QTextEdit.ExtraSelection()

sources/pyside6/tests/QtWidgets/bug_576.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def onButtonDestroyed(self, button):
2727
@unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
2828
def testWidgetParent(self):
2929
self._destroyed = False
30-
app = QApplication(sys.argv)
30+
app = QApplication(sys.argv) # noqa: F841
3131
w = QWidget()
3232

3333
b = QPushButton("test")

sources/pyside6/tests/QtWidgets/bug_585.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
class Bug585(unittest.TestCase):
2020
@unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
2121
def testCase(self):
22-
app = QApplication([])
22+
app = QApplication([]) # noqa: F841
2323
self._tree = QTreeWidget()
2424
self._tree.setColumnCount(2)
2525
i1 = QTreeWidgetItem(self._tree, ['1', ])
26-
i2 = QTreeWidgetItem(self._tree, ['2', ])
26+
i2 = QTreeWidgetItem(self._tree, ['2', ]) # noqa: F841
2727
refCount = sys.getrefcount(i1)
2828

2929
# this function return None

sources/pyside6/tests/QtWidgets/bug_674.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestBug679(unittest.TestCase):
1818
'''QGraphicsScene::clear() is missing'''
1919
@unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount")
2020
def testIt(self):
21-
app = QApplication([])
21+
app = QApplication([]) # noqa: F841
2222

2323
scene = QGraphicsScene()
2424
hello = scene.addText("Hello")

sources/pyside6/tests/QtWidgets/customproxywidget_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def testCustomProxyWidget(self):
3939
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
4040
view.show()
4141

42-
timer = QTimer.singleShot(100, self.app.quit)
42+
QTimer.singleShot(100, self.app.quit)
4343
self.app.exec()
4444

4545

sources/pyside6/tests/QtWidgets/keep_reference_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def createModelAndSetToView(view):
8484
view.setModel(model)
8585
view = QTableView()
8686
createModelAndSetToView(view)
87-
model = view.model()
87+
model = view.model() # noqa: F841
8888

8989

9090
if __name__ == '__main__':

sources/pyside6/tests/QtWidgets/qgraphicsproxywidget_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def testQGraphicsProxyWidget(self):
3434
view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
3535
view.show()
3636

37-
timer = QTimer.singleShot(100, self.app.quit)
37+
QTimer.singleShot(100, self.app.quit)
3838
self.app.exec()
3939

4040

sources/pyside6/tests/QtWidgets/qmainwindow_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def testRefCountToNull(self):
5656
self.assertEqual(sys.getrefcount(c), 2)
5757
w.setCentralWidget(c)
5858
self.assertEqual(sys.getrefcount(c), 3)
59-
wr = weakref.ref(c, self.objDel)
59+
wr = weakref.ref(c, self.objDel) # noqa: F841
6060
w.setCentralWidget(None)
6161
c = None
6262
self.app.exec()
@@ -73,7 +73,7 @@ def testRefCountToAnother(self):
7373
w.setCentralWidget(c2)
7474
self.assertEqual(sys.getrefcount(c2), 3)
7575

76-
wr = weakref.ref(c, self.objDel)
76+
wr = weakref.ref(c, self.objDel) # noqa: F841
7777
w.setCentralWidget(None)
7878
c = None
7979

sources/pyside6/tests/QtWidgets/qpushbutton_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def testSetMenu(self):
3434
w = MyWidget()
3535
w.show()
3636

37-
timer = QTimer.singleShot(100, self.app.quit)
37+
QTimer.singleShot(100, self.app.quit)
3838
self.app.exec()
3939

4040
def buttonCb(self, checked):

0 commit comments

Comments
 (0)