Skip to content

Commit

Permalink
Using augmented assignements (in-place operators) where possible (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jun 4, 2024
1 parent 457bda8 commit 60d7236
Show file tree
Hide file tree
Showing 108 changed files with 446 additions and 474 deletions.
12 changes: 6 additions & 6 deletions AutoDuck/BuildHHP.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle_globs(lGlobs):
new = glob.glob(g)
if len(new) == 0:
print(f"The pattern '{g}' yielded no files!")
lFiles = lFiles + new
lFiles.extend(new)
# lFiles is now the list of origin files.
# Normalize all of the paths:
cFiles = len(lFiles)
Expand All @@ -52,9 +52,9 @@ def handle_globs(lGlobs):
while i < cFiles:
if not os.path.isfile(lFiles[i]):
del lFiles[i]
cFiles = cFiles - 1
cFiles -= 1
continue
i = i + 1
i += 1
# Find the common prefix of all of the files
sCommonPrefix = os.path.commonprefix(lFiles)
# Damn - more commonprefix problems
Expand Down Expand Up @@ -111,12 +111,12 @@ def main():
shutil.copyfile(lSrcFiles[i], file)

for file in lDestFiles:
html_files = html_files + f"{html_dir}\\{file}\n"
html_files += f"{html_dir}\\{file}\n"

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

f.write(sHHPFormat % {"output": output, "target": target, "html_files": html_files})
f.close()
Expand Down
6 changes: 3 additions & 3 deletions AutoDuck/InsertExternalOverviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ def processFile(input, out, extLinksHTML, extTopicHTML, importantHTML):
def genHTML(doc):
s = ""
for cat in doc:
s = s + f"<H3>{cat.label}</H3>\n"
s += f"<H3>{cat.label}</H3>\n"
dict = {}
for item in cat.overviewItems.items:
dict[item.name] = item.href
keys = list(dict.keys())
keys.sort()
for k in keys:
s = s + f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
s += f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
return s


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


Expand Down
14 changes: 7 additions & 7 deletions AutoDuck/makedfromi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def GetComments(line, lineNo, lines):
doc = ""
if len(data) == 2:
doc = data[1].strip()
lineNo = lineNo + 1
lineNo += 1
while lineNo < len(lines):
line = lines[lineNo]
data = line.split("//", 2)
Expand All @@ -24,10 +24,10 @@ def GetComments(line, lineNo, lines):
if data[1].strip().startswith("@"):
# new command
break
doc = doc + "\n// " + data[1].strip()
lineNo = lineNo + 1
doc += "\n// " + data[1].strip()
lineNo += 1
# This line doesn't match - step back
lineNo = lineNo - 1
lineNo -= 1
return doc, lineNo


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

lineNo = lineNo + 1
lineNo += 1

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

outFile.write("\n")
for meth, extras in these_methods:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Coming in build 307, as yet unreleased
* Use byte-string (`b""`) for constant bytes values instead of superfluous `.encode` calls (#2046, @Avasam)
* Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam)
* Removed duplicated declarations, constants and definitions (#2050 , #1950, #1990, @Avasam)
* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam)
* 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)

### adodbapi
Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/Demos/app/basictimerapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def OnTimer(self, id, timeVal):
if nextTime:
timeDiffSeconds = nextTime - now
timeDiffMinutes = int(timeDiffSeconds / 60)
timeDiffSeconds = timeDiffSeconds % 60
timeDiffSeconds %= 60
timeDiffHours = int(timeDiffMinutes / 60)
timeDiffMinutes = timeDiffMinutes % 60
timeDiffMinutes %= 60
self.dlg.prompt1.SetWindowText(
"Next connection due in %02d:%02d:%02d"
% (timeDiffHours, timeDiffMinutes, timeDiffSeconds)
Expand Down Expand Up @@ -200,7 +200,7 @@ def SetFirstTime(self, now):
lst[pos] = 0
ret = time.mktime(tuple(lst))
if bAdd:
ret = ret + self.timeAdd
ret += self.timeAdd
return ret

def SetNextTime(self, lastTime, now):
Expand Down
10 changes: 5 additions & 5 deletions Pythonwin/pywin/Demos/app/customprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def OnDraw(self, dc):
delta = 2
colors = list(self.colors.keys())
colors.sort()
colors = colors * 2
colors *= 2
for color in colors:
if oldPen is None:
oldPen = dc.SelectObject(self.pens[color])
Expand All @@ -58,7 +58,7 @@ def OnDraw(self, dc):
dc.LineTo((x - delta, y - delta))
dc.LineTo((delta, y - delta))
dc.LineTo((delta, delta))
delta = delta + 4
delta += 4
if x - delta <= 0 or y - delta <= 0:
break
dc.SelectObject(oldPen)
Expand Down Expand Up @@ -108,10 +108,10 @@ def OnPrint(self, dc, pInfo):
cyChar = metrics["tmHeight"]
left, top, right, bottom = pInfo.GetDraw()
dc.TextOut(0, 2 * cyChar, doc.GetTitle())
top = top + (7 * cyChar) / 2
top += 7 * cyChar / 2
dc.MoveTo(left, top)
dc.LineTo(right, top)
top = top + cyChar
top += cyChar
# this seems to have not effect...
# get what I want with the dc.SetWindowOrg calls
pInfo.SetDraw((left, top, right, bottom))
Expand All @@ -131,7 +131,7 @@ def OnPrint(self, dc, pInfo):
y = (3 * cyChar) / 2

dc.TextOut(x, y, doc.GetTitle())
y = y + cyChar
y += cyChar


class PrintDemoApp(app.CApp):
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/cmdserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def Test():
while num < 1000:
print("Hello there no " + str(num))
win32api.Sleep(50)
num = num + 1
num += 1


class flags:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/dlgtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def OnNotify(self, controlid, code):
# kill focus for the edit box.
# Simply increment the value in the text box.
def KillFocus(self, msg):
self.counter = self.counter + 1
self.counter += 1
if self.edit is not None:
self.edit.SetWindowText(str(self.counter))

Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/Demos/ocx/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def __init__(self):

def OnFSCommand(self, command, args):
print("FSCommend", command, args)
self.x = self.x + 20
self.y = self.y + 20
self.angle = self.angle + 20
self.x += 20
self.y += 20
self.angle += 20
if self.x > 200 or self.y > 200:
self.x = 0
self.y = 0
Expand Down
14 changes: 7 additions & 7 deletions Pythonwin/pywin/Demos/openGLDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def ComponentFromIndex(i, nbits, shift):
# val = (unsigned char) (i >> shift);
val = (i >> shift) & 0xF
if nbits == 1:
val = val & 0x1
val &= 0x1
return oneto8[val]
elif nbits == 2:
val = val & 0x3
val &= 0x3
return twoto8[val]
elif nbits == 3:
val = val & 0x7
val &= 0x7
return threeto8[val]
else:
return 0
Expand All @@ -72,7 +72,7 @@ def PreCreateWindow(self, cc):
# include CS_PARENTDC for the class style. Refer to SetPixelFormat
# documentation in the "Comments" section for further information.
style = cc[5]
style = style | win32con.WS_CLIPSIBLINGS | win32con.WS_CLIPCHILDREN
style |= win32con.WS_CLIPSIBLINGS | win32con.WS_CLIPCHILDREN
cc = cc[0], cc[1], cc[2], cc[3], cc[4], style, cc[6], cc[7], cc[8]
cc = self._obj_.PreCreateWindow(cc)
return cc
Expand Down Expand Up @@ -287,9 +287,9 @@ def DrawScene(self):
glRotatef(self.wAngleY, 0.0, 1.0, 0.0)
glRotatef(self.wAngleZ, 0.0, 0.0, 1.0)

self.wAngleX = self.wAngleX + 1.0
self.wAngleY = self.wAngleY + 10.0
self.wAngleZ = self.wAngleZ + 5.0
self.wAngleX += 1.0
self.wAngleY += 10.0
self.wAngleZ += 5.0

glBegin(GL_QUAD_STRIP)
glColor3f(1.0, 0.0, 1.0)
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def OnInitDialog(self):
def OnOK(self):
# NB: StepIt wraps at the end if you increment past the upper limit!
# self.pbar.StepIt()
self.progress = self.progress + self.pincr
self.progress += self.pincr
if self.progress > 100:
self.progress = 100
if self.progress <= 100:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/threadedgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def OnDestroy(self, msg):
timer.kill_timer(self.timerid)

def OnTimer(self, id, timeVal):
self.index = self.index + self.incr
self.index += self.incr
if self.index > len(self.text):
self.incr = -1
self.index = len(self.text)
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def CreateWindow(self, parent):
list.InsertColumn(0, itemDetails)
col = 1
for title, width in self.columns[1:]:
col = col + 1
col += 1
itemDetails = (commctrl.LVCFMT_LEFT, width, title, 0)
list.InsertColumn(col, itemDetails)
parent.HookNotify(self.OnListEndLabelEdit, LVN_ENDLABELEDIT)
Expand Down Expand Up @@ -746,7 +746,7 @@ def run(self, cmd, globals=None, locals=None, start_stepping=1):
self.prep_run(cmd)
sys.settrace(self.trace_dispatch)
if not isinstance(cmd, types.CodeType):
cmd = cmd + "\n"
cmd += "\n"
try:
try:
if start_stepping:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/dialogs/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def FillList(self):
for col in self.colHeadings:
itemDetails = (commctrl.LVCFMT_LEFT, int(width / numCols), col, 0)
self.itemsControl.InsertColumn(index, itemDetails)
index = index + 1
index += 1
index = 0
for items in self.items:
index = self.itemsControl.InsertItem(index + 1, str(items[0]), 0)
Expand Down
Loading

0 comments on commit 60d7236

Please sign in to comment.