Skip to content

Commit 60d7236

Browse files
authored
Using augmented assignements (in-place operators) where possible (#2274)
1 parent 457bda8 commit 60d7236

File tree

108 files changed

+446
-474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+446
-474
lines changed

AutoDuck/BuildHHP.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def handle_globs(lGlobs):
4141
new = glob.glob(g)
4242
if len(new) == 0:
4343
print(f"The pattern '{g}' yielded no files!")
44-
lFiles = lFiles + new
44+
lFiles.extend(new)
4545
# lFiles is now the list of origin files.
4646
# Normalize all of the paths:
4747
cFiles = len(lFiles)
@@ -52,9 +52,9 @@ def handle_globs(lGlobs):
5252
while i < cFiles:
5353
if not os.path.isfile(lFiles[i]):
5454
del lFiles[i]
55-
cFiles = cFiles - 1
55+
cFiles -= 1
5656
continue
57-
i = i + 1
57+
i += 1
5858
# Find the common prefix of all of the files
5959
sCommonPrefix = os.path.commonprefix(lFiles)
6060
# Damn - more commonprefix problems
@@ -111,12 +111,12 @@ def main():
111111
shutil.copyfile(lSrcFiles[i], file)
112112

113113
for file in lDestFiles:
114-
html_files = html_files + f"{html_dir}\\{file}\n"
114+
html_files += f"{html_dir}\\{file}\n"
115115

116116
for cat in doc:
117-
html_files = html_files + f"{output_dir}\\{cat.id}.html\n"
117+
html_files += f"{output_dir}\\{cat.id}.html\n"
118118
for suffix in "_overview _modules _objects _constants".split():
119-
html_files = html_files + f"{output_dir}\\{cat.id}{suffix}.html\n"
119+
html_files += f"{output_dir}\\{cat.id}{suffix}.html\n"
120120

121121
f.write(sHHPFormat % {"output": output, "target": target, "html_files": html_files})
122122
f.close()

AutoDuck/InsertExternalOverviews.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ def processFile(input, out, extLinksHTML, extTopicHTML, importantHTML):
2525
def genHTML(doc):
2626
s = ""
2727
for cat in doc:
28-
s = s + f"<H3>{cat.label}</H3>\n"
28+
s += f"<H3>{cat.label}</H3>\n"
2929
dict = {}
3030
for item in cat.overviewItems.items:
3131
dict[item.name] = item.href
3232
keys = list(dict.keys())
3333
keys.sort()
3434
for k in keys:
35-
s = s + f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
35+
s += f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
3636
return s
3737

3838

3939
def genLinksHTML(links):
4040
s = ""
4141
for link in links:
42-
s = s + f'<LI><A HREF="{link.href}">{link.name}</A>\n'
42+
s += f'<LI><A HREF="{link.href}">{link.name}</A>\n'
4343
return s
4444

4545

AutoDuck/makedfromi.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def GetComments(line, lineNo, lines):
1313
doc = ""
1414
if len(data) == 2:
1515
doc = data[1].strip()
16-
lineNo = lineNo + 1
16+
lineNo += 1
1717
while lineNo < len(lines):
1818
line = lines[lineNo]
1919
data = line.split("//", 2)
@@ -24,10 +24,10 @@ def GetComments(line, lineNo, lines):
2424
if data[1].strip().startswith("@"):
2525
# new command
2626
break
27-
doc = doc + "\n// " + data[1].strip()
28-
lineNo = lineNo + 1
27+
doc += "\n// " + data[1].strip()
28+
lineNo += 1
2929
# This line doesn't match - step back
30-
lineNo = lineNo - 1
30+
lineNo -= 1
3131
return doc, lineNo
3232

3333

@@ -87,7 +87,7 @@ def make_doc_summary(inFile, outFile):
8787
_, msg, _ = sys.exc_info()
8888
print("Line %d is badly formed - %s" % (lineNo, msg))
8989

90-
lineNo = lineNo + 1
90+
lineNo += 1
9191

9292
# autoduck seems to crash when > ~97 methods. Loop multiple times,
9393
# creating a synthetic module name when this happens.
@@ -106,9 +106,9 @@ def make_doc_summary(inFile, outFile):
106106
if chunk_number == 0:
107107
pass
108108
elif chunk_number == 1:
109-
thisModName = thisModName + " (more)"
109+
thisModName += " (more)"
110110
else:
111-
thisModName = thisModName + " (more %d)" % (chunk_number + 1,)
111+
thisModName += " (more %d)" % (chunk_number + 1,)
112112

113113
outFile.write("\n")
114114
for meth, extras in these_methods:

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Coming in build 307, as yet unreleased
137137
* Use byte-string (`b""`) for constant bytes values instead of superfluous `.encode` calls (#2046, @Avasam)
138138
* Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam)
139139
* Removed duplicated declarations, constants and definitions (#2050 , #1950, #1990, @Avasam)
140+
* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam)
140141
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217)
141142

142143
### adodbapi

Pythonwin/pywin/Demos/app/basictimerapp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def OnTimer(self, id, timeVal):
144144
if nextTime:
145145
timeDiffSeconds = nextTime - now
146146
timeDiffMinutes = int(timeDiffSeconds / 60)
147-
timeDiffSeconds = timeDiffSeconds % 60
147+
timeDiffSeconds %= 60
148148
timeDiffHours = int(timeDiffMinutes / 60)
149-
timeDiffMinutes = timeDiffMinutes % 60
149+
timeDiffMinutes %= 60
150150
self.dlg.prompt1.SetWindowText(
151151
"Next connection due in %02d:%02d:%02d"
152152
% (timeDiffHours, timeDiffMinutes, timeDiffSeconds)
@@ -200,7 +200,7 @@ def SetFirstTime(self, now):
200200
lst[pos] = 0
201201
ret = time.mktime(tuple(lst))
202202
if bAdd:
203-
ret = ret + self.timeAdd
203+
ret += self.timeAdd
204204
return ret
205205

206206
def SetNextTime(self, lastTime, now):

Pythonwin/pywin/Demos/app/customprint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def OnDraw(self, dc):
4747
delta = 2
4848
colors = list(self.colors.keys())
4949
colors.sort()
50-
colors = colors * 2
50+
colors *= 2
5151
for color in colors:
5252
if oldPen is None:
5353
oldPen = dc.SelectObject(self.pens[color])
@@ -58,7 +58,7 @@ def OnDraw(self, dc):
5858
dc.LineTo((x - delta, y - delta))
5959
dc.LineTo((delta, y - delta))
6060
dc.LineTo((delta, delta))
61-
delta = delta + 4
61+
delta += 4
6262
if x - delta <= 0 or y - delta <= 0:
6363
break
6464
dc.SelectObject(oldPen)
@@ -108,10 +108,10 @@ def OnPrint(self, dc, pInfo):
108108
cyChar = metrics["tmHeight"]
109109
left, top, right, bottom = pInfo.GetDraw()
110110
dc.TextOut(0, 2 * cyChar, doc.GetTitle())
111-
top = top + (7 * cyChar) / 2
111+
top += 7 * cyChar / 2
112112
dc.MoveTo(left, top)
113113
dc.LineTo(right, top)
114-
top = top + cyChar
114+
top += cyChar
115115
# this seems to have not effect...
116116
# get what I want with the dc.SetWindowOrg calls
117117
pInfo.SetDraw((left, top, right, bottom))
@@ -131,7 +131,7 @@ def OnPrint(self, dc, pInfo):
131131
y = (3 * cyChar) / 2
132132

133133
dc.TextOut(x, y, doc.GetTitle())
134-
y = y + cyChar
134+
y += cyChar
135135

136136

137137
class PrintDemoApp(app.CApp):

Pythonwin/pywin/Demos/cmdserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def Test():
5252
while num < 1000:
5353
print("Hello there no " + str(num))
5454
win32api.Sleep(50)
55-
num = num + 1
55+
num += 1
5656

5757

5858
class flags:

Pythonwin/pywin/Demos/dlgtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def OnNotify(self, controlid, code):
5050
# kill focus for the edit box.
5151
# Simply increment the value in the text box.
5252
def KillFocus(self, msg):
53-
self.counter = self.counter + 1
53+
self.counter += 1
5454
if self.edit is not None:
5555
self.edit.SetWindowText(str(self.counter))
5656

Pythonwin/pywin/Demos/ocx/flash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def __init__(self):
3333

3434
def OnFSCommand(self, command, args):
3535
print("FSCommend", command, args)
36-
self.x = self.x + 20
37-
self.y = self.y + 20
38-
self.angle = self.angle + 20
36+
self.x += 20
37+
self.y += 20
38+
self.angle += 20
3939
if self.x > 200 or self.y > 200:
4040
self.x = 0
4141
self.y = 0

Pythonwin/pywin/Demos/openGLDemo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def ComponentFromIndex(i, nbits, shift):
5050
# val = (unsigned char) (i >> shift);
5151
val = (i >> shift) & 0xF
5252
if nbits == 1:
53-
val = val & 0x1
53+
val &= 0x1
5454
return oneto8[val]
5555
elif nbits == 2:
56-
val = val & 0x3
56+
val &= 0x3
5757
return twoto8[val]
5858
elif nbits == 3:
59-
val = val & 0x7
59+
val &= 0x7
6060
return threeto8[val]
6161
else:
6262
return 0
@@ -72,7 +72,7 @@ def PreCreateWindow(self, cc):
7272
# include CS_PARENTDC for the class style. Refer to SetPixelFormat
7373
# documentation in the "Comments" section for further information.
7474
style = cc[5]
75-
style = style | win32con.WS_CLIPSIBLINGS | win32con.WS_CLIPCHILDREN
75+
style |= win32con.WS_CLIPSIBLINGS | win32con.WS_CLIPCHILDREN
7676
cc = cc[0], cc[1], cc[2], cc[3], cc[4], style, cc[6], cc[7], cc[8]
7777
cc = self._obj_.PreCreateWindow(cc)
7878
return cc
@@ -287,9 +287,9 @@ def DrawScene(self):
287287
glRotatef(self.wAngleY, 0.0, 1.0, 0.0)
288288
glRotatef(self.wAngleZ, 0.0, 0.0, 1.0)
289289

290-
self.wAngleX = self.wAngleX + 1.0
291-
self.wAngleY = self.wAngleY + 10.0
292-
self.wAngleZ = self.wAngleZ + 5.0
290+
self.wAngleX += 1.0
291+
self.wAngleY += 10.0
292+
self.wAngleZ += 5.0
293293

294294
glBegin(GL_QUAD_STRIP)
295295
glColor3f(1.0, 0.0, 1.0)

0 commit comments

Comments
 (0)