Skip to content

Commit 8f1f4ec

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 493aba1 commit 8f1f4ec

File tree

33 files changed

+153
-138
lines changed

33 files changed

+153
-138
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ jobs:
107107
- run: pip install isort pycln
108108
- run: pycln . --config=pycln.toml --check
109109
- run: isort . --diff --check-only
110+
- uses: chartboost/ruff-action@v1
111+
with:
112+
version: '0.3.4'
110113
- uses: psf/black@stable
111114
with:
112115
options: "--fast --check --diff --verbose"

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ repos:
3333
- id: isort
3434
name: isort (python)
3535
verbose: true
36+
- repo: https://github.com/astral-sh/ruff-pre-commit
37+
rev: v0.3.4
38+
hooks:
39+
- id: ruff # Run the linter.
40+
args: [--fix]
3641
- repo: https://github.com/psf/black-pre-commit-mirror
3742
rev: 24.2.0
3843
hooks:

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/framework/interact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def ExtractCommand(self, lines):
477477
while end >= start:
478478
thisLine = self.DoGetLine(end)
479479
promptLen = len(GetPromptPrefix(thisLine))
480-
retList = [thisLine[promptLen:]] + retList
480+
retList = [thisLine[promptLen:], *retList]
481481
end = end - 1
482482
return retList
483483

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/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def __setattr__(self, attr, value):
565565
args, defArgs = self._prop_map_put_[attr]
566566
except KeyError:
567567
raise AttributeError(f"'{repr(self)}' object has no attribute '{attr}'")
568-
self._oleobj_.Invoke(*(args + (value,) + defArgs))
568+
self._oleobj_.Invoke(*((*args, value, *defArgs)))
569569

570570
def _get_good_single_object_(self, obj, obUserName=None, resultCLSID=None):
571571
return _get_good_single_object_(obj, obUserName, resultCLSID)

com/win32com/client/dynamic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __call__(self, *args):
213213
pythoncom.DISPID_VALUE,
214214
)
215215
if invkind is not None:
216-
allArgs = (dispid, LCID, invkind, 1) + args
216+
allArgs = (dispid, LCID, invkind, 1, *args)
217217
return self._get_good_object_(
218218
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
219219
)
@@ -335,7 +335,7 @@ def __setitem__(self, index, *args):
335335
pythoncom.DISPID_VALUE,
336336
)
337337
if invkind is not None:
338-
allArgs = (dispid, LCID, invkind, 0, index) + args
338+
allArgs = (dispid, LCID, invkind, 0, index, *args)
339339
return self._get_good_object_(
340340
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
341341
)
@@ -358,7 +358,7 @@ def _find_dispatch_type_(self, methodName):
358358

359359
def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
360360
result = self._oleobj_.InvokeTypes(
361-
*(dispid, LCID, wFlags, retType, argTypes) + args
361+
*(dispid, LCID, wFlags, retType, argTypes, *args)
362362
)
363363
return self._get_good_object_(result, user, resultCLSID)
364364

@@ -451,7 +451,7 @@ def _proc_(self, name, *args):
451451
item = self._olerepr_.mapFuncs[name]
452452
dispId = item.dispid
453453
return self._get_good_object_(
454-
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + (args))
454+
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0, *args))
455455
)
456456
except KeyError:
457457
raise AttributeError(name)

0 commit comments

Comments
 (0)