diff options
author | Neil <nyamatongwe@gmail.com> | 2023-03-15 09:45:15 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-03-15 09:45:15 +1100 |
commit | 481b5651df9bd160d4ff1f1ba471eead61a53252 (patch) | |
tree | d1fdb9642eaaef49eab6675dc816a7f7246f93b9 | |
parent | f5b5b395e2c21c6c8a338a2b2641e3143534589c (diff) | |
download | scintilla-mirror-481b5651df9bd160d4ff1f1ba471eead61a53252.tar.gz |
Fix some warnings from ruff.
-rw-r--r-- | scripts/Face.py | 3 | ||||
-rw-r--r-- | scripts/FileGenerator.py | 28 | ||||
-rw-r--r-- | scripts/GenerateCaseConvert.py | 10 | ||||
-rw-r--r-- | scripts/HeaderCheck.py | 4 | ||||
-rw-r--r-- | scripts/ScintillaData.py | 16 | ||||
-rw-r--r-- | test/ScintillaCallable.py | 8 | ||||
-rw-r--r-- | test/XiteWin.py | 17 | ||||
-rw-r--r-- | test/performanceTests.py | 2 | ||||
-rw-r--r-- | test/simpleTests.py | 13 | ||||
-rw-r--r-- | test/win32Tests.py | 9 |
10 files changed, 56 insertions, 54 deletions
diff --git a/scripts/Face.py b/scripts/Face.py index 21fc67995..58ec47ae8 100644 --- a/scripts/Face.py +++ b/scripts/Face.py @@ -5,7 +5,8 @@ # Requires Python 2.7 or later def sanitiseLine(line): - if line[-1:] == '\n': line = line[:-1] + if line[-1:] == '\n': + line = line[:-1] if line.find("##") != -1: line = line[:line.find("##")] line = line.strip() diff --git a/scripts/FileGenerator.py b/scripts/FileGenerator.py index bedb16b2f..d35c93955 100644 --- a/scripts/FileGenerator.py +++ b/scripts/FileGenerator.py @@ -143,16 +143,16 @@ def UpdateLineInPlistFile(path, key, value): lines = [] keyCurrent = "" with codecs.open(path, "rb", "utf-8") as f: - for l in f.readlines(): - ls = l.strip() + for line in f.readlines(): + ls = line.strip() if ls.startswith("<key>"): keyCurrent = ls.replace("<key>", "").replace("</key>", "") elif ls.startswith("<string>"): if keyCurrent == key: - start, tag, rest = l.partition("<string>") + start, tag, rest = line.partition("<string>") _val, etag, end = rest.partition("</string>") - l = start + tag + value + etag + end - lines.append(l) + line = start + tag + value + etag + end + lines.append(line) contents = "".join(lines) UpdateFile(path, contents) @@ -160,13 +160,13 @@ def UpdateLineInFile(path, linePrefix, lineReplace): lines = [] updated = False with codecs.open(path, "r", "utf-8") as f: - for l in f.readlines(): - l = l.rstrip() - if not updated and l.startswith(linePrefix): + for line in f.readlines(): + line = line.rstrip() + if not updated and line.startswith(linePrefix): lines.append(lineReplace) updated = True else: - lines.append(l) + lines.append(line) if not updated: print(f"{path}:0: Can't find '{linePrefix}'") contents = lineEnd.join(lines) + lineEnd @@ -176,7 +176,7 @@ def ReadFileAsList(path): """Read all the lnes in the file and return as a list of strings without line ends. """ with codecs.open(path, "r", "utf-8") as f: - return [l.rstrip('\n') for l in f] + return [line.rstrip('\n') for line in f] def UpdateFileFromLines(path, lines, lineEndToUse): """Join the lines with the lineEndToUse then update file if the result is different. @@ -194,19 +194,19 @@ def FindSectionInList(lines, markers): start = -1 end = -1 state = 0 - for i, l in enumerate(lines): - if markers[0] in l: + for i, line in enumerate(lines): + if markers[0] in line: if markers[1]: state = 1 else: start = i+1 state = 2 elif state == 1: - if markers[1] in l: + if markers[1] in line: start = i+1 state = 2 elif state == 2: - if markers[2] in l: + if markers[2] in line: end = i state = 3 # Check that section was found diff --git a/scripts/GenerateCaseConvert.py b/scripts/GenerateCaseConvert.py index 3c0193ecb..50f992ae6 100644 --- a/scripts/GenerateCaseConvert.py +++ b/scripts/GenerateCaseConvert.py @@ -21,11 +21,11 @@ import itertools, string, sys from FileGenerator import Regenerate -def contiguousRanges(l, diff): - # l is s list of lists +def contiguousRanges(ll, diff): + # ll is a list of lists # group into lists where first element of each element differs by diff - out = [[l[0]]] - for s in l[1:]: + out = [[ll[0]]] + for s in ll[1:]: if s[0] != out[-1][-1][0] + diff: out.append([]) out[-1].append(s) @@ -99,7 +99,7 @@ def groupRanges(symmetrics): rangeCoverage = list(flatten([range(r[0], r[0]+r[2]*r[3], r[3]) for r in rangeGroups])) - nonRanges = [(l, u) for l, u, _d in symmetrics if l not in rangeCoverage] + nonRanges = [(x, u) for x, u, _d in symmetrics if x not in rangeCoverage] return rangeGroups, nonRanges diff --git a/scripts/HeaderCheck.py b/scripts/HeaderCheck.py index e24cfa1a9..2c953bf30 100644 --- a/scripts/HeaderCheck.py +++ b/scripts/HeaderCheck.py @@ -16,11 +16,11 @@ def HeaderFromIncludeLine(s): def ExtractHeaders(file): with file.open(encoding="cp437") as infile: - return [HeaderFromIncludeLine(l) for l in infile if IsHeader(l)] + return [HeaderFromIncludeLine(h) for h in infile if IsHeader(h)] def ExtractWithPrefix(file, prefix): with file.open(encoding="cp437") as infile: - return [l.strip()[len(prefix):] for l in infile if l.startswith(prefix)] + return [s.strip()[len(prefix):] for s in infile if s.startswith(prefix)] def ExcludeName(name, excludes): return any(exclude in name for exclude in excludes) diff --git a/scripts/ScintillaData.py b/scripts/ScintillaData.py index 857da7dd5..044ecfb01 100644 --- a/scripts/ScintillaData.py +++ b/scripts/ScintillaData.py @@ -25,15 +25,15 @@ def FindCredits(historyFile, removeLinks=True): credits = [] stage = 0 with historyFile.open(encoding="utf-8") as f: - for l in f.readlines(): - l = l.strip() - if stage == 0 and l == "<table>": + for line in f.readlines(): + line = line.strip() + if stage == 0 and line == "<table>": stage = 1 - elif stage == 1 and l == "</table>": + elif stage == 1 and line == "</table>": stage = 2 - if stage == 1 and l.startswith("<td>"): - credit = l[4:-5] - if removeLinks and "<a" in l: + if stage == 1 and line.startswith("<td>"): + credit = line[4:-5] + if removeLinks and "<a" in line: title, _a, rest = credit.partition("<a href=") urlplus, _bracket, end = rest.partition(">") name = end.split("<")[0] @@ -54,7 +54,7 @@ class ScintillaData: self.versionCommad = self.versionDotted.replace(".", ", ") + ', 0' with (scintillaRoot / "doc" / "index.html").open() as f: - self.dateModified = [l for l in f.readlines() if "Date.Modified" in l]\ + self.dateModified = [d for d in f.readlines() if "Date.Modified" in d]\ [0].split('\"')[3] # 20130602 # index.html, SciTE.html diff --git a/test/ScintillaCallable.py b/test/ScintillaCallable.py index 126281aac..2f12c6ba8 100644 --- a/test/ScintillaCallable.py +++ b/test/ScintillaCallable.py @@ -2,9 +2,9 @@ from __future__ import unicode_literals -import ctypes, os, sys +import ctypes -from ctypes import c_int, c_ulong, c_char_p, c_wchar_p, c_ushort, c_uint, c_long, c_ssize_t +from ctypes import c_int, c_char_p, c_long, c_ssize_t def IsEnumeration(t): return t[:1].isupper() @@ -52,7 +52,7 @@ class SciCall: self._ptr = ptr self._msg = msg self._stringResult = stringResult - def __call__(self, w=0, l=0): + def __call__(self, w=0, lp=0): ww = ctypes.cast(w, c_char_p) if self._stringResult: lengthBytes = self._fn(self._ptr, self._msg, ww, None) @@ -63,7 +63,7 @@ class SciCall: assert lengthBytes == lengthBytes2 return bytearray(result)[:lengthBytes] else: - ll = ctypes.cast(l, c_char_p) + ll = ctypes.cast(lp, c_char_p) return self._fn(self._ptr, self._msg, ww, ll) sciFX = ctypes.CFUNCTYPE(c_ssize_t, c_char_p, c_int, c_char_p, c_char_p) diff --git a/test/XiteWin.py b/test/XiteWin.py index 1321448c6..9acf6ebfd 100644 --- a/test/XiteWin.py +++ b/test/XiteWin.py @@ -8,8 +8,7 @@ from __future__ import unicode_literals import os, platform, sys, unittest import ctypes -from ctypes import wintypes -from ctypes import c_int, c_ulong, c_char_p, c_wchar_p, c_ushort, c_uint, c_long +from ctypes import c_int, c_char_p, c_wchar_p, c_ushort, c_uint from ctypes.wintypes import HWND, WPARAM, LPARAM, HANDLE, HBRUSH, LPCWSTR user32=ctypes.windll.user32 gdi32=ctypes.windll.gdi32 @@ -248,11 +247,11 @@ class XiteWin(): def Invalidate(self): user32.InvalidateRect(self.win, 0, 0) - def WndProc(self, h, m, w, l): + def WndProc(self, h, m, wp, lp): user32.DefWindowProcW.argtypes = [HWND, c_uint, WPARAM, LPARAM] ms = sgsm.get(m, "XXX") if trace: - print("%s %s %s %s" % (hex(h)[2:],ms,w,l)) + print("%s %s %s %s" % (hex(h)[2:],ms,wp,lp)) if ms == "WM_CLOSE": user32.PostQuitMessage(0) elif ms == "WM_CREATE": @@ -260,20 +259,20 @@ class XiteWin(): return 0 elif ms == "WM_SIZE": # Work out size - if w != 1: + if wp != 1: self.OnSize() return 0 elif ms == "WM_COMMAND": - cmdCode = w & 0xffff + cmdCode = wp & 0xffff if cmdCode in self.cmds: self.Command(self.cmds[cmdCode]) return 0 elif ms == "WM_ACTIVATE": - if w != WA_INACTIVE: + if wp != WA_INACTIVE: self.FocusOnEditor() return 0 else: - return user32.DefWindowProcW(h, m, w, l) + return user32.DefWindowProcW(h, m, wp, lp) return 0 def Command(self, name): @@ -506,7 +505,7 @@ class XiteWin(): self.Open() def CmdSave(self): - if (self.fullPath == None) or (len(self.fullPath) == 0): + if (self.fullPath is None) or (len(self.fullPath) == 0): self.SaveAs() else: self.Save() diff --git a/test/performanceTests.py b/test/performanceTests.py index a3df73465..e9eff9e6a 100644 --- a/test/performanceTests.py +++ b/test/performanceTests.py @@ -5,7 +5,7 @@ from __future__ import with_statement from __future__ import unicode_literals -import os, string, sys, time, unittest +import string, time, unittest try: start = time.perf_counter() diff --git a/test/simpleTests.py b/test/simpleTests.py index 9f1b97c98..485147d6a 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -414,7 +414,7 @@ class TestSimple(unittest.TestCase): self.xite.ChooseLexer(b"cpp") self.ed.SetCodePage(65001) self.ed.SetLineEndTypesAllowed(1) - text = b"x\xe2\x80\xa9y"; + text = b"x\xe2\x80\xa9y" self.ed.AddText(5, text) self.assertEquals(self.ed.LineCount, 2) @@ -501,7 +501,7 @@ class TestSimple(unittest.TestCase): self.xite.ChooseLexer(b"cpp") self.ed.SetCodePage(65001) self.ed.SetLineEndTypesAllowed(1) - text = b"x\xc2\x85y"; + text = b"x\xc2\x85y" self.ed.AddText(4, text) self.assertEquals(self.ed.LineCount, 2) @@ -1165,8 +1165,10 @@ class TestMarkers(unittest.TestCase): def testTwiceAddedDelete(self): handle = self.ed.MarkerAdd(1,1) + self.assertNotEqual(handle, -1) self.assertEquals(self.ed.MarkerGet(1), 2) handle2 = self.ed.MarkerAdd(1,1) + self.assertNotEqual(handle2, -1) self.assertEquals(self.ed.MarkerGet(1), 2) self.ed.MarkerDelete(1,1) self.assertEquals(self.ed.MarkerGet(1), 2) @@ -1207,7 +1209,9 @@ class TestMarkers(unittest.TestCase): def testMarkerNext(self): self.assertEquals(self.ed.MarkerNext(0, 2), -1) h1 = self.ed.MarkerAdd(0,1) + self.assertNotEqual(h1, -1) h2 = self.ed.MarkerAdd(2,1) + self.assertNotEqual(h2, -1) self.assertEquals(self.ed.MarkerNext(0, 2), 0) self.assertEquals(self.ed.MarkerNext(1, 2), 2) self.assertEquals(self.ed.MarkerNext(2, 2), 2) @@ -2448,8 +2452,6 @@ class TestIndices(unittest.TestCase): def testUTF16(self): self.assertEquals(self.ed.GetLineCharacterIndex(), self.ed.SC_LINECHARACTERINDEX_NONE) - t = "aå\U00010348flﬔ-" - tv = t.encode("UTF-8") self.ed.SetContents(self.tv) self.ed.AllocateLineCharacterIndex(self.ed.SC_LINECHARACTERINDEX_UTF16) self.assertEquals(self.ed.IndexPositionFromLine(0, self.ed.SC_LINECHARACTERINDEX_UTF16), 0) @@ -2821,7 +2823,8 @@ class TestSubStyles(unittest.TestCase): def testSecondary(self): inactiveDistance = self.ed.DistanceToSecondaryStyles() - self.assertEquals(self.ed.GetPrimaryStyleFromStyle(self.ed.SCE_C_IDENTIFIER+inactiveDistance), self.ed.SCE_C_IDENTIFIER) + inactiveIdentifier = self.ed.SCE_C_IDENTIFIER+inactiveDistance + self.assertEquals(self.ed.GetPrimaryStyleFromStyle(inactiveIdentifier), self.ed.SCE_C_IDENTIFIER) class TestCallTip(unittest.TestCase): diff --git a/test/win32Tests.py b/test/win32Tests.py index 974f6ceae..d1fc3652f 100644 --- a/test/win32Tests.py +++ b/test/win32Tests.py @@ -10,11 +10,10 @@ from __future__ import with_statement from __future__ import unicode_literals -import codecs, ctypes, os, sys, unittest +import ctypes, unittest -from MessageNumbers import msgs, sgsm +from MessageNumbers import msgs -import ctypes user32 = ctypes.windll.user32 import XiteWin as Xite @@ -32,8 +31,8 @@ class TestWins(unittest.TestCase): # Helper methods - def Send(self, msg, w, l): - return user32.SendMessageW(self.sciHwnd, msgs[msg], w, l) + def Send(self, msg, wp, lp): + return user32.SendMessageW(self.sciHwnd, msgs[msg], wp, lp) def GetTextLength(self): return self.Send("WM_GETTEXTLENGTH", 0, 0) |