diff --git a/comtypes/test/__init__.py b/comtypes/test/__init__.py index 4df7c51c..8b168e7a 100644 --- a/comtypes/test/__init__.py +++ b/comtypes/test/__init__.py @@ -64,7 +64,7 @@ def requires(resource, msg=None): return if not is_resource_enabled(resource): if msg is None: - msg = "Use of the `%s' resource not enabled" % resource + msg = f"Use of the `{resource}` resource not enabled" raise ResourceDenied(msg) @@ -94,12 +94,10 @@ def get_tests(package, mask, verbosity): except ResourceDenied as detail: skipped.append(modname) if verbosity > 1: - print("Skipped %s: %s" % (modname, detail), file=sys.stderr) + print(f"Skipped {modname}: {detail}", file=sys.stderr) continue except Exception as detail: - print( - "Warning: could not import %s: %s" % (modname, detail), file=sys.stderr - ) + print(f"Warning: could not import {modname}: {detail}", file=sys.stderr) continue for name in dir(mod): if name.startswith("_"): @@ -149,9 +147,9 @@ def cleanup(): cleanup() refcounts[i] = sys.gettotalrefcount() - rc if [_f for _f in refcounts if _f]: - print("%s leaks:\n\t" % testcase, refcounts) + print(f"{testcase} leaks:\n\t", refcounts) elif verbosity: - print("%s: ok." % testcase) + print(f"{testcase}: ok.") class TestRunner(unittest.TextTestRunner): @@ -180,21 +178,21 @@ def run(self, test, skipped): len(skipped) != 1 and "s" or "", ) ) - self.stream.writeln("Unavailable resources: %s" % ", ".join(requested)) + self.stream.writeln(f"Unavailable resources: {', '.join(requested)}") else: self.stream.writeln( - "Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken) + f"Ran {run} test{'s' if run != 1 else ''} in {timeTaken:.3f}s" ) self.stream.writeln() if not result.wasSuccessful(): self.stream.write("FAILED (") failed, errored = list(map(len, (result.failures, result.errors))) if failed: - self.stream.write("failures=%d" % failed) + self.stream.write(f"failures={failed}") if errored: if failed: self.stream.write(", ") - self.stream.write("errors=%d" % errored) + self.stream.write(f"errors={errored}") self.stream.writeln(")") else: self.stream.writeln("OK") diff --git a/comtypes/typeinfo.py b/comtypes/typeinfo.py index 4a3bf152..59f437a8 100644 --- a/comtypes/typeinfo.py +++ b/comtypes/typeinfo.py @@ -680,13 +680,7 @@ class tagTLIBATTR(ctypes.Structure): wLibFlags: int def __repr__(self): - return "TLIBATTR(GUID=%s, Version=%s.%s, LCID=%s, FLags=0x%x)" % ( - self.guid, - self.wMajorVerNum, - self.wMinorVerNum, - self.lcid, - self.wLibFlags, - ) + return f"TLIBATTR(GUID={self.guid}, Version={self.wMajorVerNum}.{self.wMinorVerNum}, LCID={self.lcid}, FLags=0x{self.wLibFlags:x})" TLIBATTR = tagTLIBATTR @@ -715,13 +709,7 @@ class tagTYPEATTR(ctypes.Structure): idldescType: "IDLDESC" def __repr__(self): - return "TYPEATTR(GUID=%s, typekind=%s, funcs=%s, vars=%s, impltypes=%s)" % ( - self.guid, - self.typekind, - self.cFuncs, - self.cVars, - self.cImplTypes, - ) + return f"TYPEATTR(GUID={self.guid}, typekind={self.typekind}, funcs={self.cFuncs}, vars={self.cVars}, impltypes={self.cImplTypes})" TYPEATTR = tagTYPEATTR @@ -745,14 +733,14 @@ class tagFUNCDESC(ctypes.Structure): def __repr__(self): return ( - "FUNCDESC(" + f"FUNCDESC(" f"memid={self.memid}, " f"cParams={self.cParams}, " f"cParamsOpt={self.cParamsOpt}, " f"callconv={self.callconv}, " - f"invkind={self.invkind,}, " + f"invkind={self.invkind}, " f"funckind={self.funckind}" - ")" + f")" )