Skip to content

Commit 8586262

Browse files
committed
Prefer unpacking over concatenating
This also opens the door to using more tuples and generators in these places for further optimizations Used Ruff to prevent regressions
1 parent 71c6017 commit 8586262

27 files changed

Lines changed: 130 additions & 129 deletions

File tree

Pythonwin/pywin/Demos/ocx/ocxserialtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def OnComm(self):
6868

6969
class TestSerDialog(dialog.Dialog):
7070
def __init__(self, *args):
71-
dialog.Dialog.__init__(*(self,) + args)
71+
dialog.Dialog.__init__(*(self, *args))
7272
self.olectl = None
7373

7474
def OnComm(self):

Pythonwin/pywin/docking/DockingBar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def CreateWindow(
9696
self._obj_.CreateWindow(wndClass, title, style, (0, 0, 0, 0), parent, id)
9797

9898
# Create the child dialog
99-
self.dialog = childCreator(*(self,) + childCreatorArgs)
99+
self.dialog = childCreator(*(self, *childCreatorArgs))
100100

101101
# use the dialog dimensions as default base dimensions
102102
assert self.dialog.IsWindow(), (

Pythonwin/pywin/framework/editor/color/coloreditor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,9 @@ def GetPythonPropertyPages(self):
631631
"""Returns a list of property pages"""
632632
from pywin.scintilla import configui
633633

634-
return EditorTemplateBase.GetPythonPropertyPages(self) + [
635-
configui.ScintillaFormatPropertyPage()
634+
return [
635+
*EditorTemplateBase.GetPythonPropertyPages(self),
636+
configui.ScintillaFormatPropertyPage(),
636637
]
637638

638639

Pythonwin/pywin/scintilla/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def configure(self, editor, subsections=None):
175175
# First, we "recursively" connect any we are based on.
176176
if subsections is None:
177177
subsections = []
178-
subsections = [""] + subsections
178+
subsections = ["", *subsections]
179179
general = self.get_data("general")
180180
if general:
181181
parents = general.get("based on", [])
@@ -224,7 +224,7 @@ def configure(self, editor, subsections=None):
224224
def get_key_binding(self, event, subsections=None):
225225
if subsections is None:
226226
subsections = []
227-
subsections = [""] + subsections
227+
subsections = ["", *subsections]
228228

229229
subsection_keymap = self.get_data("keys")
230230
for subsection in subsections:

Pythonwin/pywin/tools/TraceCollector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def CollectorThread(stopEvent, file):
3838

3939
class WindowOutput(winout.WindowOutput):
4040
def __init__(self, *args):
41-
winout.WindowOutput.__init__(*(self,) + args)
41+
winout.WindowOutput.__init__(*(self, *args))
4242
self.hStopThread = win32event.CreateEvent(None, 0, 0, None)
4343
_thread.start_new(CollectorThread, (self.hStopThread, self))
4444

com/win32com/client/dynamic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def __call__(self, *args):
209209
pythoncom.DISPID_VALUE,
210210
)
211211
if invkind is not None:
212-
allArgs = (dispid, LCID, invkind, 1) + args
212+
allArgs = (dispid, LCID, invkind, 1, *args)
213213
return self._get_good_object_(
214214
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
215215
)
@@ -331,7 +331,7 @@ def __setitem__(self, index, *args):
331331
pythoncom.DISPID_VALUE,
332332
)
333333
if invkind is not None:
334-
allArgs = (dispid, LCID, invkind, 0, index) + args
334+
allArgs = (dispid, LCID, invkind, 0, index, *args)
335335
return self._get_good_object_(
336336
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
337337
)
@@ -354,7 +354,7 @@ def _find_dispatch_type_(self, methodName):
354354

355355
def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
356356
result = self._oleobj_.InvokeTypes(
357-
*(dispid, LCID, wFlags, retType, argTypes) + args
357+
*(dispid, LCID, wFlags, retType, argTypes, *args)
358358
)
359359
return self._get_good_object_(result, user, resultCLSID)
360360

@@ -447,7 +447,7 @@ def _proc_(self, name, *args):
447447
item = self._olerepr_.mapFuncs[name]
448448
dispId = item.dispid
449449
return self._get_good_object_(
450-
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + (args))
450+
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0, *args))
451451
)
452452
except KeyError:
453453
raise AttributeError(name)

com/win32com/demos/connect.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
class ConnectableServer(win32com.server.connect.ConnectableServer):
2121
_public_methods_ = [
22-
"DoIt"
23-
] + win32com.server.connect.ConnectableServer._public_methods_
22+
"DoIt",
23+
*win32com.server.connect.ConnectableServer._public_methods_,
24+
]
2425
_connect_interfaces_ = [IID_IConnectDemoEvents]
2526

2627
# The single public method that the client can call on us

com/win32com/demos/ietoolbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def toparam(self):
9898
val = default
9999
vals.append(val)
100100
full_fmt += fmt
101-
return struct.pack(*(full_fmt,) + tuple(vals))
101+
return struct.pack(*(full_fmt, *tuple(vals)))
102102

103103

104104
class TBBUTTON(WIN32STRUCT):

com/win32com/server/connect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _BroadcastNotify(self, broadcaster, extraArgs):
7777
# Ignores clients that fail.
7878
for interface in self.connections.values():
7979
try:
80-
broadcaster(*(interface,) + extraArgs)
80+
broadcaster(*(interface, *extraArgs))
8181
except pythoncom.com_error as details:
8282
self._OnNotifyFail(interface, details)
8383

com/win32com/test/testIterators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ def suite():
137137

138138

139139
if __name__ == "__main__":
140-
unittest.main(argv=sys.argv + ["suite"])
140+
unittest.main(argv=[*sys.argv, "suite"])

0 commit comments

Comments
 (0)