Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer unpacking over concatenating #2230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ jobs:
- run: pip install isort pycln
- run: pycln . --config=pycln.toml --check
- run: isort . --diff --check-only
- uses: chartboost/ruff-action@v1
with:
version: '0.3.4'
- uses: psf/black@stable
with:
options: "--fast --check --diff --verbose"
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ repos:
- id: isort
name: isort (python)
verbose: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff # Run the linter.
args: [--fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/ocx/ocxserialtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def OnComm(self):

class TestSerDialog(dialog.Dialog):
def __init__(self, *args):
dialog.Dialog.__init__(*(self,) + args)
dialog.Dialog.__init__(*(self, *args))
self.olectl = None

def OnComm(self):
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/docking/DockingBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def CreateWindow(
self._obj_.CreateWindow(wndClass, title, style, (0, 0, 0, 0), parent, id)

# Create the child dialog
self.dialog = childCreator(*(self,) + childCreatorArgs)
self.dialog = childCreator(*(self, *childCreatorArgs))

# use the dialog dimensions as default base dimensions
assert self.dialog.IsWindow(), (
Expand Down
5 changes: 3 additions & 2 deletions Pythonwin/pywin/framework/editor/color/coloreditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,9 @@ def GetPythonPropertyPages(self):
"""Returns a list of property pages"""
from pywin.scintilla import configui

return EditorTemplateBase.GetPythonPropertyPages(self) + [
configui.ScintillaFormatPropertyPage()
return [
*EditorTemplateBase.GetPythonPropertyPages(self),
configui.ScintillaFormatPropertyPage(),
]


Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def ExtractCommand(self, lines):
while end >= start:
thisLine = self.DoGetLine(end)
promptLen = len(GetPromptPrefix(thisLine))
retList = [thisLine[promptLen:]] + retList
retList = [thisLine[promptLen:], *retList]
end = end - 1
return retList

Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def configure(self, editor, subsections=None):
# First, we "recursively" connect any we are based on.
if subsections is None:
subsections = []
subsections = [""] + subsections
subsections = ["", *subsections]
general = self.get_data("general")
if general:
parents = general.get("based on", [])
Expand Down Expand Up @@ -224,7 +224,7 @@ def configure(self, editor, subsections=None):
def get_key_binding(self, event, subsections=None):
if subsections is None:
subsections = []
subsections = [""] + subsections
subsections = ["", *subsections]

subsection_keymap = self.get_data("keys")
for subsection in subsections:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/tools/TraceCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def CollectorThread(stopEvent, file):

class WindowOutput(winout.WindowOutput):
def __init__(self, *args):
winout.WindowOutput.__init__(*(self,) + args)
winout.WindowOutput.__init__(*(self, *args))
self.hStopThread = win32event.CreateEvent(None, 0, 0, None)
_thread.start_new(CollectorThread, (self.hStopThread, self))

Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def __setattr__(self, attr, value):
args, defArgs = self._prop_map_put_[attr]
except KeyError:
raise AttributeError(f"'{repr(self)}' object has no attribute '{attr}'")
self._oleobj_.Invoke(*(args + (value,) + defArgs))
self._oleobj_.Invoke(*((*args, value, *defArgs)))

def _get_good_single_object_(self, obj, obUserName=None, resultCLSID=None):
return _get_good_single_object_(obj, obUserName, resultCLSID)
Expand Down
8 changes: 4 additions & 4 deletions com/win32com/client/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __call__(self, *args):
pythoncom.DISPID_VALUE,
)
if invkind is not None:
allArgs = (dispid, LCID, invkind, 1) + args
allArgs = (dispid, LCID, invkind, 1, *args)
return self._get_good_object_(
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
)
Expand Down Expand Up @@ -335,7 +335,7 @@ def __setitem__(self, index, *args):
pythoncom.DISPID_VALUE,
)
if invkind is not None:
allArgs = (dispid, LCID, invkind, 0, index) + args
allArgs = (dispid, LCID, invkind, 0, index, *args)
return self._get_good_object_(
self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None
)
Expand All @@ -358,7 +358,7 @@ def _find_dispatch_type_(self, methodName):

def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *args):
result = self._oleobj_.InvokeTypes(
*(dispid, LCID, wFlags, retType, argTypes) + args
*(dispid, LCID, wFlags, retType, argTypes, *args)
)
return self._get_good_object_(result, user, resultCLSID)

Expand Down Expand Up @@ -451,7 +451,7 @@ def _proc_(self, name, *args):
item = self._olerepr_.mapFuncs[name]
dispId = item.dispid
return self._get_good_object_(
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0) + (args))
self._oleobj_.Invoke(*(dispId, LCID, item.desc[4], 0, *args))
)
except KeyError:
raise AttributeError(name)
Expand Down
5 changes: 3 additions & 2 deletions com/win32com/demos/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

class ConnectableServer(win32com.server.connect.ConnectableServer):
_public_methods_ = [
"DoIt"
] + win32com.server.connect.ConnectableServer._public_methods_
"DoIt",
*win32com.server.connect.ConnectableServer._public_methods_,
]
_connect_interfaces_ = [IID_IConnectDemoEvents]

# The single public method that the client can call on us
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/demos/ietoolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def toparam(self):
val = default
vals.append(val)
full_fmt += fmt
return struct.pack(*(full_fmt,) + tuple(vals))
return struct.pack(*(full_fmt, *tuple(vals)))


class TBBUTTON(WIN32STRUCT):
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _BroadcastNotify(self, broadcaster, extraArgs):
# Ignores clients that fail.
for interface in self.connections.values():
try:
broadcaster(*(interface,) + extraArgs)
broadcaster(*(interface, *extraArgs))
except pythoncom.com_error as details:
self._OnNotifyFail(interface, details)

Expand Down
2 changes: 1 addition & 1 deletion com/win32com/server/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def RegisterServer(
if addPyComCat is None:
addPyComCat = pythoncom.frozen == 0
if addPyComCat:
catids = catids + [CATID_PythonCOMServer]
catids = [*catids, CATID_PythonCOMServer]

# Set up the implemented categories
if catids:
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/testIterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ def suite():


if __name__ == "__main__":
unittest.main(argv=sys.argv + ["suite"])
unittest.main(argv=[*sys.argv, "suite"])
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def BuildModule(module, built_nodes, rootNode, create_node_fn, create_node_args)
# print("keeping", module.__name__)
node = ModuleTreeNode(module)
built_nodes[module] = node
realNode = create_node_fn(*(node,) + create_node_args)
realNode = create_node_fn(*(node, *create_node_args))
node.realNode = realNode

# Split into parent nodes.
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class EnumDebugPropertyInfo(ListEnumeratorGateway):

"""

_public_methods_ = ListEnumeratorGateway._public_methods_ + ["GetCount"]
_public_methods_ = [*ListEnumeratorGateway._public_methods_, "GetCount"]
_com_interfaces_ = [axdebug.IID_IEnumDebugPropertyInfo]

def GetCount(self):
Expand Down
19 changes: 11 additions & 8 deletions com/win32comext/axdebug/gateways.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ def GetDocumentClassId(self):


class DebugDocumentProvider(DebugDocumentInfo):
_public_methods_ = DebugDocumentInfo._public_methods_ + ["GetDocument"]
_com_interfaces_ = DebugDocumentInfo._com_interfaces_ + [
axdebug.IID_IDebugDocumentProvider
_public_methods_ = [*DebugDocumentInfo._public_methods_, "GetDocument"]
_com_interfaces_ = [
*DebugDocumentInfo._com_interfaces_,
axdebug.IID_IDebugDocumentProvider,
]

def GetDocument(self):
Expand All @@ -92,8 +93,9 @@ class DebugApplicationNode(DebugDocumentProvider):
+ DebugDocumentProvider._public_methods_
)
_com_interfaces_ = [
axdebug.IID_IDebugDocumentProvider
] + DebugDocumentProvider._com_interfaces_
axdebug.IID_IDebugDocumentProvider,
*DebugDocumentProvider._com_interfaces_,
]

def __init__(self):
DebugDocumentProvider.__init__(self)
Expand Down Expand Up @@ -153,13 +155,13 @@ class DebugDocument(DebugDocumentInfo):
"""The base interface to all debug documents."""

_public_methods_ = DebugDocumentInfo._public_methods_
_com_interfaces_ = [axdebug.IID_IDebugDocument] + DebugDocumentInfo._com_interfaces_
_com_interfaces_ = [axdebug.IID_IDebugDocument, *DebugDocumentInfo._com_interfaces_]


class DebugDocumentText(DebugDocument):
"""The interface to a text only debug document."""

_com_interfaces_ = [axdebug.IID_IDebugDocumentText] + DebugDocument._com_interfaces_
_com_interfaces_ = [axdebug.IID_IDebugDocumentText, *DebugDocument._com_interfaces_]
_public_methods_ = [
"GetDocumentAttributes",
"GetSize",
Expand All @@ -168,7 +170,8 @@ class DebugDocumentText(DebugDocument):
"GetText",
"GetPositionOfContext",
"GetContextOfPosition",
] + DebugDocument._public_methods_
*DebugDocument._public_methods_,
]

def __init__(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axscript/client/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def profile(fn, *args):
try:
# roll on 1.6 :-)
# return prof.runcall(fn, *args)
return prof.runcall(*(fn,) + args)
return prof.runcall(*(fn, *args))
finally:
import pstats

Expand Down
3 changes: 2 additions & 1 deletion com/win32comext/shell/demos/servers/column_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from win32com.shell import shell, shellcon

IPersist_Methods = ["GetClassID"]
IColumnProvider_Methods = IPersist_Methods + [
IColumnProvider_Methods = [
*IPersist_Methods,
"Initialize",
"GetColumnInfo",
"GetItemData",
Expand Down
10 changes: 6 additions & 4 deletions com/win32comext/shell/shellcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,10 +1210,11 @@ def EIRESID(x):
"ContextSensitiveHelp",
] # XXX - this should be somewhere in win32com
IPersist_Methods = ["GetClassID"]
IPersistFolder_Methods = IPersist_Methods + ["Initialize"]
IPersistFolder2_Methods = IPersistFolder_Methods + ["GetCurFolder"]
IPersistFolder_Methods = [*IPersist_Methods, "Initialize"]
IPersistFolder2_Methods = [*IPersistFolder_Methods, "GetCurFolder"]
IShellExtInit_Methods = ["Initialize"]
IShellView_Methods = IOleWindow_Methods + [
IShellView_Methods = [
*IOleWindow_Methods,
"TranslateAccelerator",
"EnableModeless",
"UIActivate",
Expand All @@ -1239,7 +1240,8 @@ def EIRESID(x):
"GetDisplayNameOf",
"SetNameOf",
]
IShellFolder2_Methods = IShellFolder_Methods + [
IShellFolder2_Methods = [
*IShellFolder_Methods,
"GetDefaultSearchGUID",
"EnumSearches",
"GetDefaultColumn",
Expand Down
2 changes: 1 addition & 1 deletion isapi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def CheckLoaderModule(dll_name):
def _CallHook(ob, hook_name, options, *extra_args):
func = getattr(ob, hook_name, None)
if func is not None:
args = (ob, options) + extra_args
args = (ob, options, *extra_args)
func(*args)


Expand Down
15 changes: 5 additions & 10 deletions pywin32_testall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# locate the dirs based on where this script is - it may be either in the
# source tree, or in an installed Python 'Scripts' tree.
this_dir = os.path.dirname(__file__)
site_packages = [
site.getusersitepackages(),
] + site.getsitepackages()
site_packages = [site.getusersitepackages(), *site.getsitepackages()]

failures = []

Expand All @@ -21,7 +19,7 @@
def run_test(script, cmdline_extras):
dirname, scriptname = os.path.split(script)
# some tests prefer to be run from their directory.
cmd = [sys.executable, "-u", scriptname] + cmdline_extras
cmd = [sys.executable, "-u", scriptname, *cmdline_extras]
print("--- Running '%s' ---" % script)
sys.stdout.flush()
result = subprocess.run(cmd, check=False, cwd=dirname)
Expand All @@ -45,7 +43,7 @@ def find_and_run(possible_locations, extras):
def main():
import argparse

code_directories = [this_dir] + site_packages
code_directories = [this_dir, *site_packages]

parser = argparse.ArgumentParser(
description="A script to trigger tests in all subprojects of PyWin32."
Expand Down Expand Up @@ -89,12 +87,9 @@ def main():
# win32com
maybes = [
os.path.join(directory, "win32com", "test", "testall.py")
for directory in [
os.path.join(this_dir, "com"),
]
+ site_packages
for directory in [os.path.join(this_dir, "com"), *site_packages]
]
extras = remains + ["1"] # only run "level 1" tests in CI
extras = [*remains, "1"] # only run "level 1" tests in CI
find_and_run(maybes, extras)

# adodbapi
Expand Down
11 changes: 11 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Target the oldest supported version
target-version = "py37"

[lint]
select = [
"RUF005", # collection-literal-concatenation
]

[lint.per-file-ignores]
# TODO: Make adodbapi changes in their own PRs
"adodbapi/*" = ["RUF005"]
Loading
Loading