Skip to content

Commit ddc14b2

Browse files
authored
Update Ruff to 0.11 (2025 formatting style introduced in 0.9) (#2458)
1 parent 469f943 commit ddc14b2

31 files changed

+277
-269
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,25 @@ jobs:
152152
cache: pip
153153
cache-dependency-path: .github/workflows/main.yml
154154
- run: pip install clang-format==18.1.* pycln
155+
# !cancelled(): Show issues even if the previous steps failed. But still fail the job
155156
- run: pycln . --config=pycln.toml --check
156-
- uses: astral-sh/ruff-action@v3
157+
- name: Run Ruff linter
158+
uses: astral-sh/ruff-action@v3
157159
with:
158-
version: "0.8.4"
159-
- run: ruff format --check
160-
- run: | # Too many files to fit in a single command, also exclude vendored Scintilla and MAPIStubLibrary
160+
version: "0.11.0"
161+
if: ${{ !cancelled() }}
162+
- name: Run Ruff formatter
163+
run: ruff format --check
164+
if: ${{ !cancelled() }}
165+
# Too many files to fit in a single command, also exclude vendored Scintilla and MAPIStubLibrary
166+
- run: |
161167
clang-format --Werror --dry-run $(git ls-files '*.cpp' ':!:com/win32comext/mapi/src/MAPIStubLibrary/')
162168
if ($LastExitCode -ne 0) { exit $LastExitCode }
169+
if: ${{ !cancelled() }}
170+
- run: |
163171
clang-format --Werror --dry-run $(git ls-files '*.h' ':!:Pythonwin/Scintilla/' ':!:com/win32comext/mapi/src/MAPIStubLibrary/')
164172
if ($LastExitCode -ne 0) { exit $LastExitCode }
173+
if: ${{ !cancelled() }}
165174
166175
mypy:
167176
runs-on: windows-2019

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
args: [--config=pycln.toml]
2727
verbose: true
2828
- repo: https://github.com/astral-sh/ruff-pre-commit
29-
rev: v0.8.4
29+
rev: v0.11.0
3030
hooks:
3131
- id: ruff # Run the linter.
3232
args: [--fix]

AutoDuck/BuildHHP.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def handle_globs(lGlobs):
6565
sCommonPrefix = os.path.split(sCommonPrefix)[0]
6666
sCommonPrefix = os.path.normpath(sCommonPrefix) + "\\"
6767
# else we have a trailing slash - it means we _expect_ it to be a patch as-is.
68-
assert (
69-
os.path.isdir(sCommonPrefix) and sCommonPrefix[-1] == "\\"
70-
), "commonprefix splitting ain't gunna work!"
68+
assert os.path.isdir(sCommonPrefix) and sCommonPrefix[-1] == "\\", (
69+
"commonprefix splitting ain't gunna work!"
70+
)
7171
print("sCommonPrefix=", sCommonPrefix)
7272
# Ok, now remove this common prefix from every file:
7373
lRelativeFiles = []

AutoDuck/document_object.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def startElement(self, name, attrs):
1313
self.document.categories.append(Category(attrs))
1414
elif name == "overviews":
1515
category = self.document.categories[-1]
16-
assert (
17-
category.overviewItems is None
18-
), f"category {category!r} already has overviews"
16+
assert category.overviewItems is None, (
17+
f"category {category!r} already has overviews"
18+
)
1919
category.overviewItems = OverviewItems(attrs)
2020
elif name == "item":
2121
item = Item(attrs)

Pythonwin/pywin/scintilla/control.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def GetSelText(self):
424424

425425
def SetSel(self, start=0, end=None):
426426
if isinstance(start, tuple):
427-
assert (
428-
end is None
429-
), "If you pass a point in the first param, the second must be None"
427+
assert end is None, (
428+
"If you pass a point in the first param, the second must be None"
429+
)
430430
start, end = start
431431
elif end is None:
432432
end = start
@@ -453,9 +453,9 @@ def GetLineCount(self):
453453
def LineFromChar(self, charPos=-1):
454454
if charPos == -1:
455455
charPos = self.GetSel()[0]
456-
assert (
457-
charPos >= 0 and charPos <= self.GetTextLength()
458-
), f"The charPos postion ({charPos}) is invalid (max={self.GetTextLength()})"
456+
assert charPos >= 0 and charPos <= self.GetTextLength(), (
457+
f"The charPos postion ({charPos}) is invalid (max={self.GetTextLength()})"
458+
)
459459
# return self.SendScintilla(EM_EXLINEFROMCHAR, charPos)
460460
# EM_EXLINEFROMCHAR puts charPos in lParam, not wParam
461461
return self.SendScintilla(EM_EXLINEFROMCHAR, 0, charPos)
@@ -476,9 +476,9 @@ def GetTextRange(self, start=0, end=-1, decode=True):
476476
if end == -1:
477477
end = self.SendScintilla(scintillacon.SCI_GETTEXTLENGTH)
478478
assert end >= start, "Negative index requested (%d/%d)" % (start, end)
479-
assert (
480-
start >= 0 and start <= self.GetTextLength()
481-
), "The start postion is invalid"
479+
assert start >= 0 and start <= self.GetTextLength(), (
480+
"The start postion is invalid"
481+
)
482482
assert end >= 0 and end <= self.GetTextLength(), "The end postion is invalid"
483483
initer = null_byte * (end - start + 1)
484484
buff = array.array("b", initer)

Pythonwin/pywin/tools/hierlist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def HierInit(self, parent, listControl=None): # Used when window first exists.
9797
else:
9898
self.listControl = listControl
9999
lbid = listControl.GetDlgCtrlID()
100-
assert (
101-
self.listBoxId is None or self.listBoxId == lbid
102-
), "An invalid listbox control ID has been specified (specified as {}, but exists as {})".format(
103-
self.listBoxId, lbid
100+
assert self.listBoxId is None or self.listBoxId == lbid, (
101+
"An invalid listbox control ID has been specified (specified as {}, but exists as {})".format(
102+
self.listBoxId, lbid
103+
)
104104
)
105105
self.listBoxId = lbid
106106
self.listControl.SetImageList(self.imageList, commctrl.LVSIL_NORMAL)

adodbapi/test/adodbapitest.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def testErrorHandlerInherits(self):
6565
mycallable = lambda connection, cursor, errorclass, errorvalue: 1
6666
conn.errorhandler = mycallable
6767
crsr = conn.cursor()
68-
assert (
69-
crsr.errorhandler == mycallable
70-
), "Error handler on crsr should be same as on connection"
68+
assert crsr.errorhandler == mycallable, (
69+
"Error handler on crsr should be same as on connection"
70+
)
7171

7272
def testDefaultErrorHandlerConnection(self):
7373
conn = self.getConnection()
@@ -97,9 +97,9 @@ def testOwnErrorHandlerConnection(self):
9797
except:
9898
pass
9999
# The Standard errorhandler appends error to messages attribute
100-
assert (
101-
len(conn.messages) > 0
102-
), "Setting errorhandler to none should bring back the standard error handler"
100+
assert len(conn.messages) > 0, (
101+
"Setting errorhandler to none should bring back the standard error handler"
102+
)
103103

104104
def testDefaultErrorHandlerCursor(self):
105105
crsr = self.getConnection().cursor()
@@ -126,9 +126,9 @@ def testOwnErrorHandlerCursor(self):
126126
except:
127127
pass
128128
# The Standard errorhandler appends error to messages attribute
129-
assert (
130-
len(crsr.messages) > 0
131-
), "Setting errorhandler to none should bring back the standard error handler"
129+
assert len(crsr.messages) > 0, (
130+
"Setting errorhandler to none should bring back the standard error handler"
131+
)
132132

133133
def testUserDefinedConversions(self):
134134
try:
@@ -645,15 +645,15 @@ def testRowIterator(self):
645645
'returned value:"%s" != test value:"%s"' % (rec[j], inParam[j])
646646
)
647647
# check that we can get a complete tuple from a row
648-
assert (
649-
tuple(rec) == inParam
650-
), f'returned value:"{rec!r}" != test value:"{inParam!r}"'
648+
assert tuple(rec) == inParam, (
649+
f'returned value:"{rec!r}" != test value:"{inParam!r}"'
650+
)
651651
# test that slices of rows work
652652
slice1 = tuple(rec[:-1])
653653
slice2 = tuple(inParam[0:2])
654-
assert (
655-
slice1 == slice2
656-
), f'returned value:"{slice1!r}" != test value:"{slice2!r}"'
654+
assert slice1 == slice2, (
655+
f'returned value:"{slice1!r}" != test value:"{slice2!r}"'
656+
)
657657
# now test named column retrieval
658658
assert rec["fldTwo"] == inParam[0]
659659
assert rec.fldThree == inParam[1]
@@ -915,9 +915,9 @@ def testRollBack(self):
915915
assert len(rs) == 1
916916
self.conn.rollback()
917917
crsr.execute(selectSql)
918-
assert (
919-
crsr.fetchone() is None
920-
), "cursor.fetchone should return None if a query retrieves no rows"
918+
assert crsr.fetchone() is None, (
919+
"cursor.fetchone should return None if a query retrieves no rows"
920+
)
921921
crsr.execute("SELECT fldData from xx_%s" % config.tmp)
922922
rs = crsr.fetchall()
923923
assert len(rs) == 9, "the original records should still be present"
@@ -973,9 +973,9 @@ def testAutoRollback(self):
973973
row = crsr.fetchone()
974974
except api.DatabaseError:
975975
row = None # if the entire table disappeared the rollback was perfect and the test passed
976-
assert (
977-
row is None
978-
), f"cursor.fetchone should return None if a query retrieves no rows. Got {row!r}"
976+
assert row is None, (
977+
f"cursor.fetchone should return None if a query retrieves no rows. Got {row!r}"
978+
)
979979
self.helpRollbackTblTemp()
980980

981981
def testAutoCommit(self):
@@ -1111,9 +1111,9 @@ def testVariableReturningStoredProcedure(self):
11111111
)
11121112
assert retvalues[0] == "Dodsworth", f'{retvalues[0]!r} is not "Dodsworth"'
11131113
assert retvalues[1] == "Anne", f'{retvalues[1]!r} is not "Anne"'
1114-
assert (
1115-
retvalues[2] == "DodsworthAnne"
1116-
), f'{retvalues[2]!r} is not "DodsworthAnne"'
1114+
assert retvalues[2] == "DodsworthAnne", (
1115+
f'{retvalues[2]!r} is not "DodsworthAnne"'
1116+
)
11171117
self.conn.rollback()
11181118

11191119
def testMultipleSetReturn(self):
@@ -1200,9 +1200,9 @@ def testIncorrectStoredProcedureParameter(self):
12001200
{"parameters": ["this is wrong", "Anne", "not Alice"]},
12011201
)
12021202
if result[0]: # the expected exception was raised
1203-
assert "@theInput" in str(result[1]) or "DatabaseError" in str(
1204-
result
1205-
), "Identifies the wrong erroneous parameter"
1203+
assert "@theInput" in str(result[1]) or "DatabaseError" in str(result), (
1204+
"Identifies the wrong erroneous parameter"
1205+
)
12061206
else:
12071207
assert result[0], result[1] # incorrect or no exception
12081208
self.conn.rollback()

adodbapi/test/adodbapitestconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,6 @@
179179
**kws,
180180
)
181181

182-
assert (
183-
doAccessTest or doSqlServerTest or doMySqlTest or doPostgresTest
184-
), "No database engine found for testing"
182+
assert doAccessTest or doSqlServerTest or doMySqlTest or doPostgresTest, (
183+
"No database engine found for testing"
184+
)

com/win32com/client/genpy.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ def _Build_CoClassChildren(self, coclass, coclass_info, oleItems, vtableItems):
931931
if clsid not in vtableItems and refAttr[11] & pythoncom.TYPEFLAG_FDUAL:
932932
refType = refType.GetRefTypeInfo(refType.GetRefTypeOfImplType(-1))
933933
refAttr = refType.GetTypeAttr()
934-
assert (
935-
refAttr.typekind == pythoncom.TKIND_INTERFACE
936-
), "must be interface bynow!"
934+
assert refAttr.typekind == pythoncom.TKIND_INTERFACE, (
935+
"must be interface bynow!"
936+
)
937937
vtableItem = VTableItem(refType, refAttr, doc)
938938
vtableItems[clsid] = vtableItem
939939
coclass.sources = list(sources.values())
@@ -965,7 +965,9 @@ def _Build_Interface(self, type_info_tuple):
965965
return oleItem, vtableItem
966966

967967
def BuildOleItemsFromType(self):
968-
assert self.bBuildHidden, "This code doesn't look at the hidden flag - I thought everyone set it true!?!?!"
968+
assert self.bBuildHidden, (
969+
"This code doesn't look at the hidden flag - I thought everyone set it true!?!?!"
970+
)
969971
oleItems = {}
970972
enumItems = {}
971973
recordItems = {}
@@ -1274,9 +1276,9 @@ def generate_child(self, child, dir):
12741276
if vtableItem is not None:
12751277
vtableItems[clsid] = vtableItem
12761278

1277-
assert (
1278-
found
1279-
), f"Can't find the '{child}' interface in the CoClasses, or the interfaces"
1279+
assert found, (
1280+
f"Can't find the '{child}' interface in the CoClasses, or the interfaces"
1281+
)
12801282
# Make a map of iid: dispitem, vtableitem)
12811283
items = {}
12821284
for key, value in oleItems.items():

com/win32com/server/register.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ def RegisterServer(
210210
# And if we are frozen, ignore the ones that don't make sense in this
211211
# context.
212212
if pythoncom.frozen:
213-
assert (
214-
sys.frozen
215-
), "pythoncom is frozen, but sys.frozen is not set - don't know the context!"
213+
assert sys.frozen, (
214+
"pythoncom is frozen, but sys.frozen is not set - don't know the context!"
215+
)
216216
if sys.frozen == "dll":
217217
clsctx &= pythoncom.CLSCTX_INPROC_SERVER
218218
else:

0 commit comments

Comments
 (0)