From a99a772b7724e028d909eb66385bba5a7ce865fb Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 4 Oct 2024 17:28:10 -0400 Subject: [PATCH] Remove redundant `str()` calls and prefer `!r` marker for `repr` in formatting --- Pythonwin/pywin/Demos/app/basictimerapp.py | 2 +- Pythonwin/pywin/Demos/cmdserver.py | 2 +- Pythonwin/pywin/Demos/objdoc.py | 2 +- Pythonwin/pywin/framework/app.py | 2 +- Pythonwin/pywin/framework/editor/vss.py | 2 +- Pythonwin/pywin/framework/intpyapp.py | 2 +- Pythonwin/pywin/framework/mdi_pychecker.py | 37 +++++++------- Pythonwin/pywin/framework/scriptutils.py | 4 +- Pythonwin/pywin/framework/sgrepmdi.py | 29 +++++------ Pythonwin/pywin/idle/AutoIndent.py | 6 +-- Pythonwin/pywin/idle/CallTips.py | 4 +- Pythonwin/pywin/scintilla/IDLEenvironment.py | 6 +-- Pythonwin/pywin/scintilla/config.py | 2 +- Pythonwin/pywin/scintilla/keycodes.py | 2 +- Pythonwin/pywin/scintilla/view.py | 4 +- Pythonwin/pywin/tools/browser.py | 15 ++---- com/win32com/client/__init__.py | 4 +- com/win32com/client/build.py | 25 ++++------ com/win32com/client/dynamic.py | 10 ++-- com/win32com/client/genpy.py | 50 ++++++++----------- com/win32com/demos/outlookAddin.py | 4 +- com/win32com/server/connect.py | 2 +- com/win32com/server/dispatcher.py | 8 ++- com/win32com/server/register.py | 4 +- com/win32com/test/testDynamic.py | 8 ++- com/win32com/test/testGatewayAddresses.py | 2 +- com/win32com/test/testPersist.py | 14 +++--- com/win32com/test/testPyComTest.py | 2 +- com/win32com/test/testvb.py | 5 +- com/win32comext/axdebug/codecontainer.py | 2 +- com/win32comext/axdebug/dump.py | 2 +- com/win32comext/axdebug/util.py | 2 +- com/win32comext/axscript/client/error.py | 4 +- com/win32comext/axscript/client/pyscript.py | 2 +- com/win32comext/axscript/test/leakTest.py | 4 +- com/win32comext/mapi/mapiutil.py | 2 +- .../shell/demos/servers/shell_view.py | 4 +- win32/Demos/EvtFormatMessage.py | 2 +- win32/Demos/GetSaveFileName.py | 12 ++--- win32/Demos/getfilever.py | 2 +- win32/Demos/pipes/runproc.py | 4 +- win32/Demos/security/GetTokenInformation.py | 4 +- win32/Demos/security/sspi/simple_auth.py | 4 +- win32/Demos/security/sspi/socket_server.py | 2 +- win32/Demos/win32wnet/testwnet.py | 2 +- win32/Lib/regutil.py | 2 +- win32/Lib/win32pdhquery.py | 2 +- win32/Lib/win32timezone.py | 2 +- win32/scripts/setup_d.py | 2 +- 49 files changed, 141 insertions(+), 180 deletions(-) diff --git a/Pythonwin/pywin/Demos/app/basictimerapp.py b/Pythonwin/pywin/Demos/app/basictimerapp.py index c60271b95..6a21715de 100644 --- a/Pythonwin/pywin/Demos/app/basictimerapp.py +++ b/Pythonwin/pywin/Demos/app/basictimerapp.py @@ -129,7 +129,7 @@ def OnTimer(self, id, timeVal): print("The last operation completed successfully.") except: t, v, tb = sys.exc_info() - str = f"Failed: {t}: {repr(v)}" + str = f"Failed: {t}: {v!r}" print(str) self.oldErr.write(str) tb = None # Prevent cycle diff --git a/Pythonwin/pywin/Demos/cmdserver.py b/Pythonwin/pywin/Demos/cmdserver.py index 4ec6e49b3..8134969cc 100644 --- a/Pythonwin/pywin/Demos/cmdserver.py +++ b/Pythonwin/pywin/Demos/cmdserver.py @@ -50,7 +50,7 @@ def write(self, str): def Test(): num = 1 while num < 1000: - print("Hello there no " + str(num)) + print("Hello there no", num) win32api.Sleep(50) num += 1 diff --git a/Pythonwin/pywin/Demos/objdoc.py b/Pythonwin/pywin/Demos/objdoc.py index fff792536..99261a03e 100644 --- a/Pythonwin/pywin/Demos/objdoc.py +++ b/Pythonwin/pywin/Demos/objdoc.py @@ -41,7 +41,7 @@ def OnOpenDocument(self, name): class object_view(docview.EditView): def OnInitialUpdate(self): - self.ReplaceSel("Object is %s" % repr(self.GetDocument().object)) + self.ReplaceSel(f"Object is {self.GetDocument().object!r}") def demo(): diff --git a/Pythonwin/pywin/framework/app.py b/Pythonwin/pywin/framework/app.py index f0c4d6d3e..401d87f5d 100644 --- a/Pythonwin/pywin/framework/app.py +++ b/Pythonwin/pywin/framework/app.py @@ -164,7 +164,7 @@ def OnIdle(self, count): try: thisRet = handler(handler, count) except: - print("Idle handler %s failed" % (repr(handler))) + print(f"Idle handler {handler!r} failed") traceback.print_exc() print("Idle handler removed from list") try: diff --git a/Pythonwin/pywin/framework/editor/vss.py b/Pythonwin/pywin/framework/editor/vss.py index 4a772acef..f3d036fd3 100644 --- a/Pythonwin/pywin/framework/editor/vss.py +++ b/Pythonwin/pywin/framework/editor/vss.py @@ -99,6 +99,6 @@ def CheckoutFile(fileName): except: typ, val, tb = sys.exc_info() traceback.print_exc() - win32ui.MessageBox(f"{str(typ)} - {str(val)}", "Error checking out file") + win32ui.MessageBox(f"{typ} - {val}", "Error checking out file") tb = None # Cleanup a cycle return ok diff --git a/Pythonwin/pywin/framework/intpyapp.py b/Pythonwin/pywin/framework/intpyapp.py index acbd34cc1..b30da8554 100644 --- a/Pythonwin/pywin/framework/intpyapp.py +++ b/Pythonwin/pywin/framework/intpyapp.py @@ -325,7 +325,7 @@ def ProcessArgs(self, args, dde=None): ) continue if dde: - dde.Exec("win32ui.GetApp().OpenDocumentFile(%s)" % (repr(fname))) + dde.Exec(f"win32ui.GetApp().OpenDocumentFile({fname!r})") else: win32ui.GetApp().OpenDocumentFile(par) elif argType == "/rundlg": diff --git a/Pythonwin/pywin/framework/mdi_pychecker.py b/Pythonwin/pywin/framework/mdi_pychecker.py index 03e5e220f..38f7412c0 100644 --- a/Pythonwin/pywin/framework/mdi_pychecker.py +++ b/Pythonwin/pywin/framework/mdi_pychecker.py @@ -289,12 +289,12 @@ def doSearch(self): ) # self.text = [] self.GetFirstView().Append( - "#Pychecker Run in " + self.dirpattern + " %s\n" % time.asctime() + f"#Pychecker Run in {self.dirpattern} {time.asctime()}\n" ) if self.verbose: - self.GetFirstView().Append("# =" + repr(self.dp.dirs) + "\n") - self.GetFirstView().Append("# Files " + self.filpattern + "\n") - self.GetFirstView().Append("# Options " + self.greppattern + "\n") + self.GetFirstView().Append(f"# ={self.dp.dirs!r}\n") + self.GetFirstView().Append(f"# Files {self.filpattern}\n") + self.GetFirstView().Append(f"# Options {self.greppattern}\n") self.fplist = self.filpattern.split(";") self.GetFirstView().Append( "# Running... ( double click on result lines in order to jump to the source code ) \n" @@ -391,7 +391,7 @@ def _inactive_idleHandler(self, handler, count): for i in range(len(lines)): line = lines[i] if self.pat.search(line) is not None: - self.GetFirstView().Append(f + "(" + repr(i + 1) + ") " + line) + self.GetFirstView().Append(f"{f} ({i + 1!r}) {line}") else: self.fndx = -1 self.fpndx += 1 @@ -417,18 +417,13 @@ def _inactive_idleHandler(self, handler, count): return 1 def GetParams(self): - return ( - self.dirpattern - + "\t" - + self.filpattern - + "\t" - + self.greppattern - + "\t" - + repr(self.casesensitive) - + "\t" - + repr(self.recurse) - + "\t" - + repr(self.verbose) + return "{}\t{}\t{}\t{!r}\t{!r}\t{!r}".format( + self.dirpattern, + self.filpattern, + self.greppattern, + self.casesensitive, + self.recurse, + self.verbose, ) def OnSaveDocument(self, filename): @@ -542,9 +537,11 @@ def OnAddComment(self, cmd, code): if view.GetTextRange(pos - 1, pos) in ("\r", "\n"): pos -= 1 view.SetSel(pos, pos) - errtext = m.group(3) - if start != end and line_start == line_end: - errtext = self.GetSelText() + errtext = ( + self.GetSelText() + if start != end and line_start == line_end + else m.group(3) + ) errtext = repr(re.escape(errtext).replace(r"\ ", " ")) view.ReplaceSel(addspecific and cmnt % locals() or cmnt) return 0 diff --git a/Pythonwin/pywin/framework/scriptutils.py b/Pythonwin/pywin/framework/scriptutils.py index 98c34b477..2cb4695c7 100644 --- a/Pythonwin/pywin/framework/scriptutils.py +++ b/Pythonwin/pywin/framework/scriptutils.py @@ -614,10 +614,10 @@ def _HandlePythonFailure(what, syntaxErrorPathName=None): _JumpToPosition(fileName, line, col) except (TypeError, ValueError): msg = str(details) - win32ui.SetStatusText("Failed to " + what + " - syntax error - %s" % msg) + win32ui.SetStatusText(f"Failed to {what} - syntax error - {msg}") else: traceback.print_exc() - win32ui.SetStatusText("Failed to " + what + " - " + str(details)) + win32ui.SetStatusText(f"Failed to {what} - {details}") tb = None # Clean up a cycle. diff --git a/Pythonwin/pywin/framework/sgrepmdi.py b/Pythonwin/pywin/framework/sgrepmdi.py index 539fe6d12..1fd49a33b 100644 --- a/Pythonwin/pywin/framework/sgrepmdi.py +++ b/Pythonwin/pywin/framework/sgrepmdi.py @@ -266,11 +266,11 @@ def doSearch(self): self.dp = dirpath(self.dirpattern, self.recurse) self.SetTitle(f"Grep for {self.greppattern} in {self.filpattern}") # self.text = [] - self.GetFirstView().Append("#Search " + self.dirpattern + "\n") + self.GetFirstView().Append(f"#Search {self.dirpattern}\n") if self.verbose: - self.GetFirstView().Append("# =" + repr(self.dp.dirs) + "\n") - self.GetFirstView().Append("# Files " + self.filpattern + "\n") - self.GetFirstView().Append("# For " + self.greppattern + "\n") + self.GetFirstView().Append(f"# ={self.dp.dirs!r}\n") + self.GetFirstView().Append(f"# Files {self.filpattern}\n") + self.GetFirstView().Append(f"# For {self.greppattern}\n") self.fplist = self.filpattern.split(";") if self.casesensitive: self.pat = re.compile(self.greppattern) @@ -303,7 +303,7 @@ def SearchFile(self, handler, count): for i in range(len(lines)): line = lines[i] if self.pat.search(line) is not None: - self.GetFirstView().Append(f + "(" + repr(i + 1) + ") " + line) + self.GetFirstView().Append(f"{f} ({i + 1!r}) {line}") else: self.fndx = -1 self.fpndx += 1 @@ -329,18 +329,13 @@ def SearchFile(self, handler, count): return 1 def GetParams(self): - return ( - self.dirpattern - + "\t" - + self.filpattern - + "\t" - + self.greppattern - + "\t" - + repr(self.casesensitive) - + "\t" - + repr(self.recurse) - + "\t" - + repr(self.verbose) + return "{}\t{}\t{}\t{!r}\t{!r}\t{!r}".format( + self.dirpattern, + self.filpattern, + self.greppattern, + self.casesensitive, + self.recurse, + self.verbose, ) def OnSaveDocument(self, filename): diff --git a/Pythonwin/pywin/idle/AutoIndent.py b/Pythonwin/pywin/idle/AutoIndent.py index e433097e9..a4e8e2ffa 100644 --- a/Pythonwin/pywin/idle/AutoIndent.py +++ b/Pythonwin/pywin/idle/AutoIndent.py @@ -101,7 +101,7 @@ def config(self, **options): elif key == "context_use_ps1": self.context_use_ps1 = value else: - raise KeyError("bad option name: %s" % repr(key)) + raise KeyError(f"bad option name: {key!r}") # If ispythonsource and guess are true, guess a good value for # indentwidth based on file content (if possible), and if @@ -230,7 +230,7 @@ def newline_and_indent_event(self, event): y = PyParse.Parser(self.indentwidth, self.tabwidth) for context in self.num_context_lines: startat = max(lno - context, 1) - startatindex = repr(startat) + ".0" + startatindex = f"{startat!r}.0" rawtext = text.get(startatindex, "insert") y.set_str(rawtext) bod = y.find_good_parse_start( @@ -500,7 +500,7 @@ def readline(self): val = "" else: i = self.i = self.i + 1 - mark = repr(i) + ".0" + mark = f"{i!r}.0" if self.text.compare(mark, ">=", "end"): val = "" else: diff --git a/Pythonwin/pywin/idle/CallTips.py b/Pythonwin/pywin/idle/CallTips.py index c15847955..03a14c255 100644 --- a/Pythonwin/pywin/idle/CallTips.py +++ b/Pythonwin/pywin/idle/CallTips.py @@ -207,9 +207,7 @@ def test(tests): expected = t.__doc__ + "\n" + t.__doc__ if get_arg_text(t) != expected: failed.append(t) - print( - f"{t} - expected {repr(expected)}, but got {repr(get_arg_text(t))}" - ) + print(f"{t} - expected {expected!r}, but got {get_arg_text(t)!r}") print("%d of %d tests failed" % (len(failed), len(tests))) tc = TC() diff --git a/Pythonwin/pywin/scintilla/IDLEenvironment.py b/Pythonwin/pywin/scintilla/IDLEenvironment.py index 773abdc13..7ce93331d 100644 --- a/Pythonwin/pywin/scintilla/IDLEenvironment.py +++ b/Pythonwin/pywin/scintilla/IDLEenvironment.py @@ -516,11 +516,7 @@ def TestCheck(index, edit, expected=None): def TestGet(fr, to, t, expected): got = t.get(fr, to) if got != expected: - print( - "ERROR: get({}, {}) expected {}, but got {}".format( - repr(fr), repr(to), repr(expected), repr(got) - ) - ) + print(f"ERROR: get({fr!r}, {to!r}) expected {expected!r}, but got {got!r}") def test(): diff --git a/Pythonwin/pywin/scintilla/config.py b/Pythonwin/pywin/scintilla/config.py index 6f5a6396f..89085ee07 100644 --- a/Pythonwin/pywin/scintilla/config.py +++ b/Pythonwin/pywin/scintilla/config.py @@ -42,7 +42,7 @@ def split_line(line, lineno): sep_pos = line.rfind("=") if sep_pos == -1: if line.strip(): - print("Warning: Line %d: %s is an invalid entry" % (lineno, repr(line))) + print(f"Warning: Line {lineno}: {line!r} is an invalid entry") return None, None return "", "" return line[:sep_pos].strip(), line[sep_pos + 1 :].strip() diff --git a/Pythonwin/pywin/scintilla/keycodes.py b/Pythonwin/pywin/scintilla/keycodes.py index d94ccda47..60de88033 100644 --- a/Pythonwin/pywin/scintilla/keycodes.py +++ b/Pythonwin/pywin/scintilla/keycodes.py @@ -144,7 +144,7 @@ def make_key_name(vk, flags): def _psc(char): sc, mods = get_vk(char) - print("Char %s -> %d -> %s" % (repr(char), sc, key_code_to_name.get(sc))) + print(f"Char {char!r} -> {sc} -> {key_code_to_name.get(sc)}") def test1(): diff --git a/Pythonwin/pywin/scintilla/view.py b/Pythonwin/pywin/scintilla/view.py index e94148750..0ab3fbd4f 100644 --- a/Pythonwin/pywin/scintilla/view.py +++ b/Pythonwin/pywin/scintilla/view.py @@ -512,9 +512,7 @@ def list2dict(l): pass except: win32ui.SetStatusText( - "Error attempting to get object attributes - {}".format( - repr(sys.exc_info()[0]) - ) + f"Error attempting to get object attributes - {sys.exc_info()[0]!r}" ) # ensure all keys are strings. diff --git a/Pythonwin/pywin/tools/browser.py b/Pythonwin/pywin/tools/browser.py index b0fd7cab1..8de1e1816 100644 --- a/Pythonwin/pywin/tools/browser.py +++ b/Pythonwin/pywin/tools/browser.py @@ -49,20 +49,13 @@ def __repr__(self): type = self.GetHLIType() except: type = "Generic" - return ( - "HLIPythonObject(" - + type - + ") - name: " - + self.name - + " object: " - + repr(self.myobject) - ) + return f"HLIPythonObject({type}) - name: {self.name} object: {self.myobject!r}" def GetText(self): try: - return str(self.name) + " (" + self.GetHLIType() + ")" + return f"{self.name} ({self.GetHLIType()})" except AttributeError: - return str(self.name) + " = " + repr(self.myobject) + return f"{self.name} = {self.myobject!r}" def InsertDocString(self, lst): ob = None @@ -260,7 +253,7 @@ def GetSubList(self): ret = [] pos = 0 for item in self.myobject: - ret.append(MakeHLI(item, "[" + str(pos) + "]")) + ret.append(MakeHLI(item, f"[{pos}]")) pos += 1 self.InsertDocString(ret) return ret diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index c0b1a8761..5a719266b 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -554,7 +554,7 @@ def _ApplyTypes_(self, dispid, wFlags, retType, argTypes, user, resultCLSID, *ar def __getattr__(self, attr): args = self._prop_map_get_.get(attr) if args is None: - raise AttributeError(f"'{repr(self)}' object has no attribute '{attr}'") + raise AttributeError(f"'{self!r}' object has no attribute '{attr}'") return self._ApplyTypes_(*args) def __setattr__(self, attr, value): @@ -564,7 +564,7 @@ def __setattr__(self, attr, value): try: args, defArgs = self._prop_map_put_[attr] except KeyError: - raise AttributeError(f"'{repr(self)}' object has no attribute '{attr}'") + raise AttributeError(f"'{self!r}' object has no attribute '{attr}'") self._oleobj_.Invoke(*(args + (value,) + defArgs)) def _get_good_single_object_(self, obj, obUserName=None, resultCLSID=None): diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index b75f21821..dec5847aa 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -113,9 +113,8 @@ def GetResultCLSIDStr(self): rc = self.GetResultCLSID() if rc is None: return "None" - return repr( - str(rc) - ) # Convert the IID object to a string, then to a string in a string. + # Convert the IID object to a string in a string. + return f"'{rc}'" def GetResultName(self): if self.resultDocumentation is None: @@ -403,7 +402,7 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1): if len(bad_params) == 0 and len(retDesc) == 2 and retDesc[1] == 0: rd = retDesc[0] if rd in NoTranslateMap: - s = "%s\treturn self._oleobj_.InvokeTypes(%d, LCID, %s, %s, %s%s)" % ( + s = "{}\treturn self._oleobj_.InvokeTypes({}, LCID, {}, {}, {}{})".format( linePrefix, id, fdesc[4], @@ -412,12 +411,12 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1): _BuildArgList(fdesc, names), ) elif rd in [pythoncom.VT_DISPATCH, pythoncom.VT_UNKNOWN]: - s = "%s\tret = self._oleobj_.InvokeTypes(%d, LCID, %s, %s, %s%s)\n" % ( + s = "{}\tret = self._oleobj_.InvokeTypes({}, LCID, {}, {}, {!r}{})\n".format( linePrefix, id, fdesc[4], retDesc, - repr(argsDesc), + argsDesc, _BuildArgList(fdesc, names), ) s += f"{linePrefix}\tif ret is not None:\n" @@ -431,29 +430,27 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1): ) s += f"{linePrefix}\t\texcept pythoncom.error:\n" s += f"{linePrefix}\t\t\treturn ret\n" - s += "{}\t\tret = Dispatch(ret, {}, {})\n".format( - linePrefix, repr(name), resclsid - ) - s += "%s\treturn ret" % linePrefix + s += f"{linePrefix}\t\tret = Dispatch(ret, {name!r}, {resclsid})\n" + s += f"{linePrefix}\treturn ret" elif rd == pythoncom.VT_BSTR: s = f"{linePrefix}\t# Result is a Unicode object\n" - s += "%s\treturn self._oleobj_.InvokeTypes(%d, LCID, %s, %s, %s%s)" % ( + s += "{}\treturn self._oleobj_.InvokeTypes({}, LCID, {}, {}, {!r}{})".format( linePrefix, id, fdesc[4], retDesc, - repr(argsDesc), + argsDesc, _BuildArgList(fdesc, names), ) # else s remains None if s is None: - s = "%s\treturn self._ApplyTypes_(%d, %s, %s, %s, %s, %s%s)" % ( + s = "{}\treturn self._ApplyTypes_({}, {}, {}, {}, {!r}, {}{})".format( linePrefix, id, fdesc[4], retDesc, argsDesc, - repr(name), + name, resclsid, _BuildArgList(fdesc, names), ) diff --git a/com/win32com/client/dynamic.py b/com/win32com/client/dynamic.py index ffe7e9e26..7604d6dd2 100644 --- a/com/win32com/client/dynamic.py +++ b/com/win32com/client/dynamic.py @@ -459,13 +459,13 @@ def _print_details_(self): print("\t", method) print("Props:") for prop, entry in self._olerepr_.propMap.items(): - print(f"\t{prop} = 0x{entry.dispid:x} - {repr(entry)}") + print(f"\t{prop} = 0x{entry.dispid:x} - {entry!r}") print("Get Props:") for prop, entry in self._olerepr_.propMapGet.items(): - print(f"\t{prop} = 0x{entry.dispid:x} - {repr(entry)}") + print(f"\t{prop} = 0x{entry.dispid:x} - {entry!r}") print("Put Props:") for prop, entry in self._olerepr_.propMapPut.items(): - print(f"\t{prop} = 0x{entry.dispid:x} - {repr(entry)}") + print(f"\t{prop} = 0x{entry.dispid:x} - {entry!r}") except: traceback.print_exc() @@ -638,9 +638,7 @@ def __setattr__(self, attr, value): return # Allow property assignment. debug_attr_print( - "SetAttr called for {}.{}={} on DispatchContainer".format( - self._username_, attr, repr(value) - ) + f"SetAttr called for {self._username_}.{attr}={value!r} on DispatchContainer" ) if self._olerepr_: diff --git a/com/win32com/client/genpy.py b/com/win32com/client/genpy.py index 6c3e7dc7f..fa8280f59 100644 --- a/com/win32com/client/genpy.py +++ b/com/win32com/client/genpy.py @@ -112,7 +112,7 @@ def __lt__(self, other): return self.order < other.order def __repr__(self): - return "OleItem: doc=%s, order=%d" % (repr(self.doc), self.order) + return f"OleItem: doc={self.doc!r}, order={self.order}" class RecordItem(build.OleItem, WritableItem): @@ -234,10 +234,7 @@ def WriteEnumerationItems(self, stream): # Sanitize it, in case the repr contains its own quotes. (??? line breaks too ???) use = use.replace('"', "'") use = ( - '"' - + use - + '"' - + " # This VARIANT type cannot be converted automatically" + f'"{use}" # This VARIANT type cannot be converted automatically' ) print( "\t%-30s=%-10s # from enum %s" @@ -343,11 +340,11 @@ def WriteClassHeader(self, generator): ) except pythoncom.com_error: pass - print("\tCLSID = " + repr(self.clsid), file=stream) + print(f"\tCLSID = {self.clsid!r}", file=stream) if self.coclass_clsid is None: print("\tcoclass_clsid = None", file=stream) else: - print("\tcoclass_clsid = " + repr(self.coclass_clsid), file=stream) + print(f"\tcoclass_clsid = {self.coclass_clsid!r}", file=stream) print(file=stream) self.bWritten = 1 @@ -365,11 +362,11 @@ def WriteEventSinkClassHeader(self, generator): ) except pythoncom.com_error: pass - print("\tCLSID = CLSID_Sink = " + repr(self.clsid), file=stream) + print(f"\tCLSID = CLSID_Sink = {self.clsid!r}", file=stream) if self.coclass_clsid is None: print("\tcoclass_clsid = None", file=stream) else: - print("\tcoclass_clsid = " + repr(self.coclass_clsid), file=stream) + print(f"\tcoclass_clsid = {self.coclass_clsid!r}", file=stream) print("\t_public_methods_ = [] # For COM Server support", file=stream) WriteSinkEventMap(self, stream) print(file=stream) @@ -806,14 +803,14 @@ def WriteClass(self, generator): if item.bWritten: key = item.python_name else: - key = repr(str(item.clsid)) # really the iid. - print("\t\t%s," % (key), file=stream) + key = f"'{item.clsid}'" # really the iid. + print(f"\t\t{key},", file=stream) print("\t]", file=stream) if defItem: if defItem.bWritten: defName = defItem.python_name else: - defName = repr(str(defItem.clsid)) # really the iid. + defName = f"'{defItem.clsid}'" # really the iid. print(f"\tdefault_source = {defName}", file=stream) print("\tcoclass_interfaces = [", file=stream) defItem = None @@ -824,14 +821,14 @@ def WriteClass(self, generator): if item.bWritten: key = item.python_name else: - key = repr(str(item.clsid)) # really the iid. + key = f"'{item.clsid}'" # really the iid. print(f"\t\t{key},", file=stream) print("\t]", file=stream) if defItem: if defItem.bWritten: defName = defItem.python_name else: - defName = repr(str(defItem.clsid)) # really the iid. + defName = f"'{defItem.clsid}'" # really the iid. print(f"\tdefault_interface = {defName}", file=stream) self.bWritten = 1 print(file=stream) @@ -1111,7 +1108,7 @@ def do_gen_file_header(self): print(build._makeDocString(docDesc), file=self.file) - print("makepy_version =", repr(makepy_version), file=self.file) + print(f"makepy_version = {makepy_version!r}", file=self.file) print(f"python_version = 0x{sys.hexversion:x}", file=self.file) print(file=self.file) print( @@ -1133,10 +1130,10 @@ def do_gen_file_header(self): print("defaultNamedNotOptArg=pythoncom.Empty", file=self.file) print("defaultUnnamedArg=pythoncom.Empty", file=self.file) print(file=self.file) - print("CLSID = " + repr(la[0]), file=self.file) - print("MajorVersion = " + str(la[3]), file=self.file) - print("MinorVersion = " + str(la[4]), file=self.file) - print("LibraryFlags = " + str(la[5]), file=self.file) + print(f"CLSID = {la[0]!r}", file=self.file) + print(f"MajorVersion = {la[3]}", file=self.file) + print(f"MinorVersion = {la[4]}", file=self.file) + print(f"LibraryFlags = {la[5]}", file=self.file) print("LCID = " + hex(la[1]), file=self.file) print(file=self.file) @@ -1188,17 +1185,14 @@ def do_generate(self): print("RecordMap = {", file=stream) for record in recordItems.values(): if record.clsid == pythoncom.IID_NULL: + record_str = f"{record.doc[0]!r}: '{record.clsid}'," print( - "\t###{}: {}, # Record disabled because it doesn't have a non-null GUID".format( - repr(record.doc[0]), repr(str(record.clsid)) - ), + f"\t###{record_str}", + "# Record disabled because it doesn't have a non-null GUID", file=stream, ) else: - print( - f"\t{repr(record.doc[0])}: {repr(str(record.clsid))},", - file=stream, - ) + print(f"\t{record_str}", file=stream) print("}", file=stream) print(file=stream) @@ -1208,7 +1202,7 @@ def do_generate(self): for item in oleItems.values(): if item is not None and item.bWritten: print( - f"\t'{str(item.clsid)}' : {item.python_name},", + f"\t'{item.clsid}' : {item.python_name},", file=stream, ) print("}", file=stream) @@ -1230,7 +1224,7 @@ def do_generate(self): for item in oleItems.values(): if item is not None: print( - f"\t'{str(item.clsid)}' : {repr(item.python_name)},", + f"\t'{item.clsid}' : {item.python_name!r},", file=stream, ) print("}", file=stream) diff --git a/com/win32com/demos/outlookAddin.py b/com/win32com/demos/outlookAddin.py index 244d5b325..a67dedafc 100644 --- a/com/win32com/demos/outlookAddin.py +++ b/com/win32com/demos/outlookAddin.py @@ -58,9 +58,7 @@ def OnItemAdd(self, item): try: print("An item was added to the inbox with subject:", item.Subject) except AttributeError: - print( - "An item was added to the inbox, but it has no subject! - ", repr(item) - ) + print(f"An item was added to the inbox, but it has no subject! - {item!r}") class OutlookAddin: diff --git a/com/win32com/server/connect.py b/com/win32com/server/connect.py index e99555a04..0127de3a1 100644 --- a/com/win32com/server/connect.py +++ b/com/win32com/server/connect.py @@ -82,4 +82,4 @@ def _BroadcastNotify(self, broadcaster, extraArgs): self._OnNotifyFail(interface, details) def _OnNotifyFail(self, interface, details): - print("Ignoring COM error to connection - %s" % (repr(details))) + print(f"Ignoring COM error to connection - {details!r}") diff --git a/com/win32com/server/dispatcher.py b/com/win32com/server/dispatcher.py index 95791a355..929d1b8df 100644 --- a/com/win32com/server/dispatcher.py +++ b/com/win32com/server/dispatcher.py @@ -153,8 +153,8 @@ def _QueryInterface_(self, iid): rc = DispatcherBase._QueryInterface_(self, iid) if not rc: self._trace_( - "in {}._QueryInterface_ with unsupported IID {} ({})".format( - repr(self.policy._obj_), IIDToInterfaceName(iid), iid + "in {!r}._QueryInterface_ with unsupported IID {} ({})".format( + self.policy._obj_, IIDToInterfaceName(iid), iid ) ) return rc @@ -222,9 +222,7 @@ def __init__(self, policyClass, object): if self.logger is None: # If we have no logger, setup our output. import win32traceutil # Sets up everything. - self._trace_( - "Object with win32trace dispatcher created (object=%s)" % repr(object) - ) + self._trace_(f"Object with win32trace dispatcher created (object={object!r})") class DispatcherOutputDebugString(DispatcherTrace): diff --git a/com/win32com/server/register.py b/com/win32com/server/register.py index 04ffdca37..f9093e05f 100644 --- a/com/win32com/server/register.py +++ b/com/win32com/server/register.py @@ -272,7 +272,7 @@ def RegisterServer( exeName = _find_localserver_exe(1) exeName = win32api.GetShortPathName(exeName) pyfile = _find_localserver_module() - command = f'{exeName} "{pyfile}" {str(clsid)}' + command = f'{exeName} "{pyfile}" {clsid}' _set_string(keyNameRoot + "\\LocalServer32", command) else: # Remove any old LocalServer32 registrations _remove_key(keyNameRoot + "\\LocalServer32") @@ -383,7 +383,7 @@ def UnregisterServer(clsid, progID=None, verProgID=None, customKeys=None): def GetRegisteredServerOption(clsid, optionName): """Given a CLSID for a server and option name, return the option value""" - keyNameRoot = f"CLSID\\{str(clsid)}\\{str(optionName)}" + keyNameRoot = f"CLSID\\{clsid}\\{optionName}" return _get_string(keyNameRoot) diff --git a/com/win32com/test/testDynamic.py b/com/win32com/test/testDynamic.py index 75765fb87..58a93e2a1 100644 --- a/com/win32com/test/testDynamic.py +++ b/com/win32com/test/testDynamic.py @@ -37,8 +37,8 @@ def write(self, *args): ) # Probably call as PROPGET. for arg in args[:-1]: - print(str(arg), end=" ") - print(str(args[-1])) + print(arg, end=" ") + print(args[-1]) def Test(): @@ -65,9 +65,7 @@ def Test(): client.TestSequence = v assert v == list( client.TestSequence - ), "Dynamic sequences not working! {!r}/{!r}".format( - repr(v), repr(client.testSequence) - ) + ), f"Dynamic sequences not working! {v!r}/{client.testSequence!r}" client.write("This", "output", "has", "come", "via", "testDynamic.py") # Check our new "_FlagAsMethod" works (kinda!) diff --git a/com/win32com/test/testGatewayAddresses.py b/com/win32com/test/testGatewayAddresses.py index aeafbec75..3904d5e90 100644 --- a/com/win32com/test/testGatewayAddresses.py +++ b/com/win32com/test/testGatewayAddresses.py @@ -60,7 +60,7 @@ def FailObjectIdentity(ob1, ob2, when): if not CheckObjectIdentity(ob1, ob2): global numErrors numErrors += 1 - print(when, f"are not identical ({repr(ob1)}, {repr(ob2)})") + print(f"{when} are not identical ({ob1!r}, {ob2!r})") class Dummy: diff --git a/com/win32com/test/testPersist.py b/com/win32com/test/testPersist.py index aecdd27fb..e47c97305 100644 --- a/com/win32com/test/testPersist.py +++ b/com/win32com/test/testPersist.py @@ -42,8 +42,8 @@ def ReadAt(self, offset, cb): return result def WriteAt(self, offset, data): - print("WriteAt " + str(offset)) - print("len " + str(len(data))) + print("WriteAt", offset) + print("len", len(data)) print("data:") # print(data) if len(self.data) >= offset: @@ -56,13 +56,13 @@ def WriteAt(self, offset, data): return len(data) def Flush(self, whatsthis=0): - print("Flush" + str(whatsthis)) + print("Flush", whatsthis) fname = os.path.join(win32api.GetTempPath(), "persist.doc") open(fname, "wb").write(self.data) return S_OK def SetSize(self, size): - print("Set Size" + str(size)) + print("Set Size", size) if size > len(self.data): self.data += b"\000" * (size - len(self.data)) else: @@ -76,7 +76,7 @@ def UnlockRegion(self, offset, size, locktype): print("UnlockRegion") def Stat(self, statflag): - print("returning Stat " + str(statflag)) + print("returning Stat", statflag) return ( "PyMemBytes", storagecon.STGTY_LOCKBYTES, @@ -121,7 +121,7 @@ def SaveObject(self): return S_OK def GetMoniker(self, dwAssign, dwWhichMoniker): - print("GetMoniker " + str(dwAssign) + " " + str(dwWhichMoniker)) + print("GetMoniker", dwAssign, dwWhichMoniker) def GetContainer(self): print("GetContainer") @@ -130,7 +130,7 @@ def ShowObject(self): print("ShowObject") def OnShowWindow(self, fShow): - print("ShowObject" + str(fShow)) + print("ShowObject", fShow) def RequestNewObjectLayout(self): print("RequestNewObjectLayout") diff --git a/com/win32com/test/testPyComTest.py b/com/win32com/test/testPyComTest.py index 4964d0a51..aa77beea5 100644 --- a/com/win32com/test/testPyComTest.py +++ b/com/win32com/test/testPyComTest.py @@ -583,7 +583,7 @@ def check_dispatch(got): def TestCounter(counter, bIsGenerated): # Test random access into container - progress("Testing counter", repr(counter)) + progress(f"Testing counter {counter!r}") import random for i in range(50): diff --git a/com/win32com/test/testvb.py b/com/win32com/test/testvb.py index ca5ab7689..1f026c45a 100644 --- a/com/win32com/test/testvb.py +++ b/com/win32com/test/testvb.py @@ -484,9 +484,10 @@ def TestStructs(vbtest): s.sub_val, ) ) - if repr(s) != expected: + repr_s = repr(s) + if repr_s != expected: print("Expected repr:", expected) - print("Actual repr :", repr(s)) + print("Actual repr :", repr_s) raise AssertionError("repr() of record object failed") print("Struct/Record tests passed") diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index d82ee0008..2b9870377 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -226,7 +226,7 @@ def GetText(self): try: self.text = open(fname, "r").read() except OSError as details: - self.text = f"# COMException opening file\n# {repr(details)}" + self.text = f"# COMException opening file\n# {details!r}" else: self.text = f"# No file available for module '{self.module}'" self._buildlines() diff --git a/com/win32comext/axdebug/dump.py b/com/win32comext/axdebug/dump.py index 61a1cfc7a..80b91d732 100644 --- a/com/win32comext/axdebug/dump.py +++ b/com/win32comext/axdebug/dump.py @@ -28,7 +28,7 @@ def DumpDebugApplicationNode(node, level=0): numLines, numChars = doctext.GetSize() # text, attr = doctext.GetText(0, 20, 1) text, attr = doctext.GetText(0, numChars, 1) - print(f"{spacer}Text is {repr(text[:40] + '...')}, {len(text)} bytes long") + print(f"{spacer}Text is '{text[:40] + '...'}', {len(text)} bytes long") else: print(f"{spacer*2}") diff --git a/com/win32comext/axdebug/util.py b/com/win32comext/axdebug/util.py index 3b4efad93..5f1035516 100644 --- a/com/win32comext/axdebug/util.py +++ b/com/win32comext/axdebug/util.py @@ -92,7 +92,7 @@ def _Invoke_(self, dispid, lcid, wFlags, args): tb = None # A cycle scode = v.scode try: - desc = " (" + str(v.description) + ")" + desc = f" ({v.description})" except AttributeError: desc = "" print(f"*** Invoke of {dispid} raised COM exception 0x{scode:x}{desc}") diff --git a/com/win32comext/axscript/client/error.py b/com/win32comext/axscript/client/error.py index 27d007ed4..231774baf 100644 --- a/com/win32comext/axscript/client/error.py +++ b/com/win32comext/axscript/client/error.py @@ -244,8 +244,8 @@ def ProcessAXScriptException( result = scriptingSite.OnScriptError(gateway) except pythoncom.com_error as details: print("**OnScriptError failed:", details) - print("Exception description:'%s'" % (repr(exceptionInstance.description))) - print("Exception text:'%s'" % (repr(exceptionInstance.linetext))) + print(f"Exception description: '{exceptionInstance.description!r}'") + print(f"Exception text: '{exceptionInstance.linetext!r}'") result = winerror.S_FALSE if result == winerror.S_OK: diff --git a/com/win32comext/axscript/client/pyscript.py b/com/win32comext/axscript/client/pyscript.py index 5bf46eb80..8c238abcb 100644 --- a/com/win32comext/axscript/client/pyscript.py +++ b/com/win32comext/axscript/client/pyscript.py @@ -111,7 +111,7 @@ def __init__(self, scriptItem): self.__dict__["_scriptItem_"] = scriptItem def __repr__(self): - return "" + return f"" def __getattr__(self, attr): # If a known subitem, return it. diff --git a/com/win32comext/axscript/test/leakTest.py b/com/win32comext/axscript/test/leakTest.py index 7b52e36a9..cc26de053 100644 --- a/com/win32comext/axscript/test/leakTest.py +++ b/com/win32comext/axscript/test/leakTest.py @@ -145,10 +145,10 @@ def doTestEngine(engine, echoer): print("***** Calling 'hello' failed", exc) return if echoer.last != "Goober": - print("***** Function call didn't set value correctly", repr(echoer.last)) + print(f"***** Function call didnt set value correctly {echoer.last!r}") if str(ob.prop) != "Property Value": - print("***** Property Value not correct - ", repr(ob.prop)) + print(f"***** Property Value not correct - {ob.prop!r}") ob.testcollection() diff --git a/com/win32comext/mapi/mapiutil.py b/com/win32comext/mapi/mapiutil.py index 896a8b0d0..3e02dbce7 100644 --- a/com/win32comext/mapi/mapiutil.py +++ b/com/win32comext/mapi/mapiutil.py @@ -203,7 +203,7 @@ def SetProperties(msg, propDict): tagType = mapitags.PT_SYSTIME else: raise ValueError( - f"The type of object {repr(val)}({type(val)}) can not be written" + f"The type of object {val!r}({type(val)}) can not be written" ) key = mapitags.PROP_TAG(tagType, mapitags.PROP_ID(newIds[newIdNo])) newIdNo += 1 diff --git a/com/win32comext/shell/demos/servers/shell_view.py b/com/win32comext/shell/demos/servers/shell_view.py index abd56bd57..0866951cd 100644 --- a/com/win32comext/shell/demos/servers/shell_view.py +++ b/com/win32comext/shell/demos/servers/shell_view.py @@ -151,7 +151,7 @@ def BindToObject(self, pidl, bc, iid): elif typ == "object": klass = ShellFolderObject else: - raise RuntimeError("What is " + repr(typ)) + raise RuntimeError(f"What is {typ!r}") ret = wrap(klass(extra), iid, useDispatcher=(debug > 0)) return ret @@ -370,7 +370,7 @@ def Initialize(self, pidl): # This is the PIDL of us, as created by the shell. This is our # top-level ID. All other items under us have PIDLs defined # by us - see the notes at the top of the file. - # print("Initialize called with pidl", repr(pidl)) + # print("Initialize called with pidl={pidl!r}") self.pidl = pidl def CreateViewObject(self, hwnd, iid): diff --git a/win32/Demos/EvtFormatMessage.py b/win32/Demos/EvtFormatMessage.py index ecd5075a7..3709e18ea 100644 --- a/win32/Demos/EvtFormatMessage.py +++ b/win32/Demos/EvtFormatMessage.py @@ -76,7 +76,7 @@ def main(): # > UnicodeEncodeError: \'charmap\' codec can\'t encode character \'\\u200e\' in position 57: character maps to \r\n' # Can't reproduce when running manually, so it seems more a subprocess.Popen() # than ours: - print(" Failed to decode:", repr(message)) + print(f" Failed to decode: {message!r}") if __name__ == "__main__": diff --git a/win32/Demos/GetSaveFileName.py b/win32/Demos/GetSaveFileName.py index 285875052..a87c561d1 100644 --- a/win32/Demos/GetSaveFileName.py +++ b/win32/Demos/GetSaveFileName.py @@ -17,9 +17,9 @@ FilterIndex=1, ) -print("save file names:", repr(fname)) -print("filter used:", repr(customfilter)) -print("Flags:", flags) +print(f"save file names: {fname!r}") +print(f"filter used: {customfilter!r}") +print(f"Flags: {flags}") for k, v in list(win32con.__dict__.items()): if k.startswith("OFN_") and flags & v: print("\t" + k) @@ -35,9 +35,9 @@ FilterIndex=0, ) -print("open file names:", repr(fname)) -print("filter used:", repr(customfilter)) -print("Flags:", flags) +print(f"open file names: {fname!r}") +print(f"filter used: {customfilter!r}") +print(f"Flags: {flags}") for k, v in list(win32con.__dict__.items()): if k.startswith("OFN_") and flags & v: print("\t" + k) diff --git a/win32/Demos/getfilever.py b/win32/Demos/getfilever.py index 402a7bc43..fa405cf92 100644 --- a/win32/Demos/getfilever.py +++ b/win32/Demos/getfilever.py @@ -26,7 +26,7 @@ ## \VarFileInfo\Translation returns list of available (language, codepage) pairs that can be used to retreive string info ## any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle two are language/codepage pair returned from above for lang, codepage in pairs: - print("lang: ", lang, "codepage:", codepage) + print("lang:", lang, "codepage:", codepage) for ver_string in ver_strings: str_info = f"\\StringFileInfo\\{lang:04X}{codepage:04X}\\{ver_string}" # print(str_inf) diff --git a/win32/Demos/pipes/runproc.py b/win32/Demos/pipes/runproc.py index 2ed02dd3d..c3f3cb211 100644 --- a/win32/Demos/pipes/runproc.py +++ b/win32/Demos/pipes/runproc.py @@ -100,10 +100,10 @@ def run(self, cmdline): self.stdin.close() self.stdout = os.fdopen(msvcrt.open_osfhandle(self.hStdout_r, 0), "rb") - print("Read on stdout: ", repr(self.stdout.read())) + print(f"Read on stdout: {self.stdout.read()!r}") self.stderr = os.fdopen(msvcrt.open_osfhandle(self.hStderr_r, 0), "rb") - print("Read on stderr: ", repr(self.stderr.read())) + print(f"Read on stderr: {self.stderr.read()!r}") if __name__ == "__main__": diff --git a/win32/Demos/security/GetTokenInformation.py b/win32/Demos/security/GetTokenInformation.py index 192c549e1..330c41c62 100644 --- a/win32/Demos/security/GetTokenInformation.py +++ b/win32/Demos/security/GetTokenInformation.py @@ -40,7 +40,7 @@ def dump_token(th): flag_names, unk = TOKEN_PRIVILEGE_ATTRIBUTES.lookup_flags(priv_flags) flag_desc = " ".join(flag_names) if unk: - flag_desc += "(" + str(unk) + ")" + flag_desc += f"({unk})" priv_name = win32security.LookupPrivilegeName("", priv_luid) priv_desc = win32security.LookupPrivilegeDisplayName("", priv_name) @@ -52,7 +52,7 @@ def dump_token(th): flag_names, unk = TOKEN_GROUP_ATTRIBUTES.lookup_flags(group_attr) flag_desc = " ".join(flag_names) if unk: - flag_desc += "(" + str(unk) + ")" + flag_desc += f"({unk})" if group_attr & TOKEN_GROUP_ATTRIBUTES.SE_GROUP_LOGON_ID: sid_desc = "Logon sid" else: diff --git a/win32/Demos/security/sspi/simple_auth.py b/win32/Demos/security/sspi/simple_auth.py index 2721ca780..9bc13373e 100644 --- a/win32/Demos/security/sspi/simple_auth.py +++ b/win32/Demos/security/sspi/simple_auth.py @@ -67,6 +67,6 @@ def lookup_ret_code(err): encbuf.append(win32security.PySecBufferType(trailersize, sspicon.SECBUFFER_TOKEN)) encbuf[0].Buffer = msg sspiclient.ctxt.EncryptMessage(0, encbuf, 1) -print("Encrypted data:", repr(encbuf[0].Buffer)) +print(f"Encrypted data: {encbuf[0].Buffer!r}") sspiserver.ctxt.DecryptMessage(encbuf, 1) -print("Unencrypted data:", encbuf[0].Buffer) +print(f"Encrypted data: {encbuf[0].Buffer}") diff --git a/win32/Demos/security/sspi/socket_server.py b/win32/Demos/security/sspi/socket_server.py index 09f005b46..3d14fee22 100644 --- a/win32/Demos/security/sspi/socket_server.py +++ b/win32/Demos/security/sspi/socket_server.py @@ -96,7 +96,7 @@ def process_request(self, request, client_address): if data is None or key is None: break data = self.sa.decrypt(data, key) - print("Client sent:", repr(data)) + print(f"Client sent: {data!r}") finally: self.sa.ctxt.RevertSecurityContext() self.close_request(request) diff --git a/win32/Demos/win32wnet/testwnet.py b/win32/Demos/win32wnet/testwnet.py index 1ddbf7d7a..3d6fbfc95 100644 --- a/win32/Demos/win32wnet/testwnet.py +++ b/win32/Demos/win32wnet/testwnet.py @@ -113,7 +113,7 @@ def TestConnection(): def TestGetUser(): u = win32wnet.WNetGetUser() - print("Current global user is", repr(u)) + print(f"Current global user is {u!r}") if u != win32wnet.WNetGetUser(None): raise RuntimeError("Default value didn't seem to work!") diff --git a/win32/Lib/regutil.py b/win32/Lib/regutil.py index cf3ab67f8..5a72bc7aa 100644 --- a/win32/Lib/regutil.py +++ b/win32/Lib/regutil.py @@ -49,7 +49,7 @@ def SetRegistryDefaultValue(subKey, value, rootkey=None): elif isinstance(value, int): typeId = win32con.REG_DWORD else: - raise TypeError("Value must be string or integer - was passed " + repr(value)) + raise TypeError(f"Value must be string or integer - was passed {value!r}") win32api.RegSetValue(rootkey, subKey, typeId, value) diff --git a/win32/Lib/win32pdhquery.py b/win32/Lib/win32pdhquery.py index 3f458e0a8..77106736d 100644 --- a/win32/Lib/win32pdhquery.py +++ b/win32/Lib/win32pdhquery.py @@ -566,6 +566,6 @@ def __init__(self, query): self.query = query def __repr__(self): - return "" % repr(self.query) + return f"" __str__ = __repr__ diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index d5605a511..93c6ae10e 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -586,7 +586,7 @@ def _LoadDynamicInfoFromKey(self, key): ) def __repr__(self): - result = f"{self.__class__.__name__}({repr(self.timeZoneName)}" + result = f"{self.__class__.__name__}({self.timeZoneName!r}" if self.fixedStandardTime: result += ", True" result += ")" diff --git a/win32/scripts/setup_d.py b/win32/scripts/setup_d.py index b458854d1..6fcb730d9 100644 --- a/win32/scripts/setup_d.py +++ b/win32/scripts/setup_d.py @@ -61,7 +61,7 @@ def _docopy(src, dest): return 1 except: print(f"Error copying '{src}' -> '{dest}'") - print(str(sys.exc_info()[1])) + print(sys.exc_info()[1]) usage_and_die(3)