Skip to content

Commit b6a500d

Browse files
committed
Manually fix remaining ruff check issues
Leaving Python 3 only fixes for now
1 parent 76146b4 commit b6a500d

File tree

6 files changed

+37
-42
lines changed

6 files changed

+37
-42
lines changed

caveats.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def parse(fname):
1111
1212
"""
1313

14-
blocks = list()
14+
blocks = []
1515
with io.open(fname, "r", encoding="utf-8") as f:
1616
in_block = False
1717
current_block = None
@@ -31,11 +31,11 @@ def parse(fname):
3131

3232
if line.startswith("```python"):
3333
in_block = True
34-
current_block = list()
34+
current_block = []
3535
current_block.append(current_header)
3636
blocks.append(current_block)
3737

38-
tests = list()
38+
tests = []
3939
for block in blocks:
4040
header = (
4141
block[0]
@@ -87,7 +87,7 @@ def format_(blocks):
8787
8888
"""
8989

90-
tests = list()
90+
tests = []
9191
function_count = 0 # For each test to have a unique name
9292

9393
for block in blocks:
@@ -99,7 +99,7 @@ def format_(blocks):
9999
)
100100

101101
# Validate binding on first line
102-
if not block["binding"] in ("PySide", "PySide2", "PyQt5", "PyQt4"):
102+
if block["binding"] not in ("PySide", "PySide2", "PyQt5", "PyQt4"):
103103
block["body"].insert(0, ">>> assert False, 'Invalid binding'\n")
104104

105105
if sys.version_info > (3, 4) and block["binding"] in ("PySide"):

examples/QtSiteConfig/main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test():
1111
sys.path.insert(0, os.path.dirname(__file__))
1212

1313
try:
14-
from Qt import QtCore
14+
from Qt import QtCore # noqa: F401
1515

1616
except ImportError:
1717
print("Qt.QtCore was successfully removed by QtSiteConfig.py")
@@ -21,9 +21,6 @@ def test():
2121
"Qt.QtCore was importable, update_members was not applied correctly."
2222
)
2323

24-
# Suppress "Qt.QtCore" imported but unused warning
25-
QtCore
26-
2724
# Test _misplaced_members is applied correctly
2825
from Qt import QtGui
2926

@@ -35,7 +32,7 @@ def test():
3532
title = "Test Widget"
3633
from Qt import QtWidgets, QtCompat
3734

38-
app = QtWidgets.QApplication(sys.argv)
35+
app = QtWidgets.QApplication(sys.argv) # noqa: F841
3936
wid = QtWidgets.QWidget()
4037
wid.setWindowTitle(title)
4138

@@ -57,8 +54,6 @@ def test():
5754
assert QtCompat.QMainWindow.windowTitleDecorator(win) == check, (
5855
"Decorated method was added to QtCompat.QMainWindow"
5956
)
60-
# Suppress "app" imported but unused warning
61-
app
6257

6358

6459
if __name__ == "__main__":

examples/loadUi/baseinstance1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setup_ui(uifile, base_instance=None):
2525
return ui
2626
else:
2727
for member in dir(ui):
28-
if not member.startswith("__") and member is not "staticMetaObject":
28+
if not member.startswith("__") and member != "staticMetaObject":
2929
setattr(base_instance, member, getattr(ui, member))
3030
return ui
3131

membership.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def generate_common_members():
314314
print("WARNING: Skipped dir() command", modname, error)
315315

316316
# Remove duplicates and sort
317-
MODULES = sorted(list(set(MODULES)))
317+
MODULES = sorted(set(MODULES))
318318

319319
if QT_VERBOSE:
320320
# Print all modules (for debugging)
@@ -336,7 +336,7 @@ def generate_common_members():
336336
# Sort and remove duplicates
337337
sorted_members = {}
338338
for key, value in members.copy().items():
339-
sorted_members[key] = sorted(list(set(value)))
339+
sorted_members[key] = sorted(set(value))
340340

341341
if QT_VERBOSE:
342342
# Debug

src/Qt.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
__version__ = "2.0.0.dev1"
5252

5353
# Enable support for `from Qt import *`
54-
__all__ = ["QtCompat"]
54+
__all__ = [
55+
"QtCompat", # noqa: F822
56+
]
5557

5658
# Flags from environment variables
5759
QT_VERBOSE = bool(os.getenv("QT_VERBOSE"))
@@ -628,13 +630,13 @@ def messageOutputHandler(*args):
628630

629631
def _getcpppointer(object):
630632
if hasattr(Qt, "_shiboken6"):
631-
return getattr(Qt, "_shiboken6").getCppPointer(object)[0]
633+
return Qt._shiboken6.getCppPointer(object)[0]
632634
elif hasattr(Qt, "_shiboken2"):
633-
return getattr(Qt, "_shiboken2").getCppPointer(object)[0]
635+
return Qt._shiboken2.getCppPointer(object)[0]
634636
elif hasattr(Qt, "_shiboken"):
635-
return getattr(Qt, "_shiboken").getCppPointer(object)[0]
637+
return Qt._shiboken.getCppPointer(object)[0]
636638
elif hasattr(Qt, "_sip"):
637-
return getattr(Qt, "_sip").unwrapinstance(object)
639+
return Qt._sip.unwrapinstance(object)
638640
raise AttributeError("'module' has no attribute 'getCppPointer'")
639641

640642

@@ -665,13 +667,13 @@ def _wrapinstance(ptr, base=None):
665667
)
666668

667669
if Qt.IsPyQt4 or Qt.IsPyQt5 or Qt.IsPyQt6:
668-
func = getattr(Qt, "_sip").wrapinstance
670+
func = Qt._sip.wrapinstance
669671
elif Qt.IsPySide2:
670-
func = getattr(Qt, "_shiboken2").wrapInstance
672+
func = Qt._shiboken2.wrapInstance
671673
elif Qt.IsPySide6:
672-
func = getattr(Qt, "_shiboken6").wrapInstance
674+
func = Qt._shiboken6.wrapInstance
673675
elif Qt.IsPySide:
674-
func = getattr(Qt, "_shiboken").wrapInstance
676+
func = Qt._shiboken.wrapInstance
675677
else:
676678
raise AttributeError("'module' has no attribute 'wrapInstance'")
677679

@@ -710,16 +712,16 @@ def _isvalid(object):
710712
711713
"""
712714
if hasattr(Qt, "_shiboken6"):
713-
return getattr(Qt, "_shiboken6").isValid(object)
715+
return Qt._shiboken6.isValid(object)
714716

715717
elif hasattr(Qt, "_shiboken2"):
716-
return getattr(Qt, "_shiboken2").isValid(object)
718+
return Qt._shiboken2.isValid(object)
717719

718720
elif hasattr(Qt, "_shiboken"):
719-
return getattr(Qt, "_shiboken").isValid(object)
721+
return Qt._shiboken.isValid(object)
720722

721723
elif hasattr(Qt, "_sip"):
722-
return not getattr(Qt, "_sip").isdeleted(object)
724+
return not Qt._sip.isdeleted(object)
723725

724726
else:
725727
raise AttributeError("'module' has no attribute isValid")
@@ -807,7 +809,7 @@ def _loadUi(uifile, baseinstance=None):
807809
context = error.__context__
808810
# Raise the exceptions that are consistent with the other bindings
809811
if isinstance(context, (IOError, ElementTree.ParseError)):
810-
raise context
812+
raise context # noqa: B904
811813
# Otherwise raise the original PyQt6 specific exception.
812814
raise
813815

@@ -1635,7 +1637,7 @@ def _build_compatibility_members(binding, decorators=None):
16351637
16361638
"""
16371639

1638-
decorators = decorators or dict()
1640+
decorators = decorators or {}
16391641

16401642
# Allow optional site-level customization of the compatibility members.
16411643
# This method does not need to be implemented in QtSiteConfig.
@@ -1692,7 +1694,7 @@ def _pyside6():
16921694
16931695
"""
16941696

1695-
import PySide6 as module
1697+
import PySide6 as module # noqa: N813
16961698

16971699
extras = ["QtSvgWidgets", "QtUiTools"]
16981700
try:
@@ -1758,7 +1760,7 @@ def _pyside2():
17581760
17591761
"""
17601762

1761-
import PySide2 as module
1763+
import PySide2 as module # noqa: N813
17621764

17631765
extras = ["QtUiTools"]
17641766
try:
@@ -1810,7 +1812,7 @@ def _pyside2():
18101812
def _pyside():
18111813
"""Initialise PySide"""
18121814

1813-
import PySide as module
1815+
import PySide as module # noqa: N813
18141816

18151817
extras = ["QtUiTools"]
18161818
try:
@@ -1866,7 +1868,7 @@ def _pyside():
18661868
def _pyqt6():
18671869
"""Initialise PyQt6"""
18681870

1869-
import PyQt6 as module
1871+
import PyQt6 as module # noqa: N813
18701872

18711873
extras = ["QtSvgWidgets", "uic"]
18721874

@@ -1906,7 +1908,7 @@ def _pyqt6():
19061908
def _pyqt5():
19071909
"""Initialise PyQt5"""
19081910

1909-
import PyQt5 as module
1911+
import PyQt5 as module # noqa: N813
19101912

19111913
extras = ["uic"]
19121914

@@ -1996,7 +1998,7 @@ def _pyqt4():
19961998
"Warning: API '%s' has already been set to %d.\n" % (api, actual)
19971999
)
19982000

1999-
import PyQt4 as module
2001+
import PyQt4 as module # noqa: N813
20002002

20012003
extras = ["uic"]
20022004
try:
@@ -2259,7 +2261,7 @@ def _install():
22592261
if preferred_order is None:
22602262
# If a json preferred binding was not used use, respect the
22612263
# QT_PREFERRED_BINDING environment variable if defined.
2262-
preferred_order = list(b for b in QT_PREFERRED_BINDING.split(os.pathsep) if b)
2264+
preferred_order = [b for b in QT_PREFERRED_BINDING.split(os.pathsep) if b]
22632265

22642266
order = preferred_order or default_order
22652267

tests.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,7 @@ def test_qtcompat_base_class():
11771177
if not QtWidgets.QApplication.instance():
11781178
app = QtWidgets.QApplication(sys.argv)
11791179
else:
1180-
app = QtWidgets.QApplication.instance()
1181-
# suppress `local variable 'app' is assigned to but never used`
1182-
app
1180+
app = QtWidgets.QApplication.instance() # noqa: F841
11831181
header = QtWidgets.QHeaderView(get_enum(Qt.QtCore.Qt, "Orientation", "Horizontal"))
11841182

11851183
# Spot check compatibility functions
@@ -1219,7 +1217,7 @@ def test_membership():
12191217
common_members.pop("QtOpenGL", None)
12201218
common_members.pop("QtMultimedia", None)
12211219

1222-
missing = list()
1220+
missing = []
12231221
for module, members in common_members.items():
12241222
missing.extend(
12251223
member for member in members if not hasattr(getattr(Qt, module), member)
@@ -1237,7 +1235,7 @@ def test_missing():
12371235

12381236
missing_members = Qt._missing_members.copy()
12391237

1240-
missing = list()
1238+
missing = []
12411239
for module, members in missing_members.items():
12421240
mod = getattr(Qt, module)
12431241
missing.extend(

0 commit comments

Comments
 (0)