Skip to content

Commit 7d1db18

Browse files
authored
replaced by fstring (#700)
1 parent 63b7f00 commit 7d1db18

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

comtypes/test/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def requires(resource, msg=None):
6464
return
6565
if not is_resource_enabled(resource):
6666
if msg is None:
67-
msg = "Use of the `%s' resource not enabled" % resource
67+
msg = f"Use of the `{resource}` resource not enabled"
6868
raise ResourceDenied(msg)
6969

7070

@@ -94,12 +94,10 @@ def get_tests(package, mask, verbosity):
9494
except ResourceDenied as detail:
9595
skipped.append(modname)
9696
if verbosity > 1:
97-
print("Skipped %s: %s" % (modname, detail), file=sys.stderr)
97+
print(f"Skipped {modname}: {detail}", file=sys.stderr)
9898
continue
9999
except Exception as detail:
100-
print(
101-
"Warning: could not import %s: %s" % (modname, detail), file=sys.stderr
102-
)
100+
print(f"Warning: could not import {modname}: {detail}", file=sys.stderr)
103101
continue
104102
for name in dir(mod):
105103
if name.startswith("_"):
@@ -149,9 +147,9 @@ def cleanup():
149147
cleanup()
150148
refcounts[i] = sys.gettotalrefcount() - rc
151149
if [_f for _f in refcounts if _f]:
152-
print("%s leaks:\n\t" % testcase, refcounts)
150+
print(f"{testcase} leaks:\n\t", refcounts)
153151
elif verbosity:
154-
print("%s: ok." % testcase)
152+
print(f"{testcase}: ok.")
155153

156154

157155
class TestRunner(unittest.TextTestRunner):
@@ -180,21 +178,21 @@ def run(self, test, skipped):
180178
len(skipped) != 1 and "s" or "",
181179
)
182180
)
183-
self.stream.writeln("Unavailable resources: %s" % ", ".join(requested))
181+
self.stream.writeln(f"Unavailable resources: {', '.join(requested)}")
184182
else:
185183
self.stream.writeln(
186-
"Ran %d test%s in %.3fs" % (run, run != 1 and "s" or "", timeTaken)
184+
f"Ran {run} test{'s' if run != 1 else ''} in {timeTaken:.3f}s"
187185
)
188186
self.stream.writeln()
189187
if not result.wasSuccessful():
190188
self.stream.write("FAILED (")
191189
failed, errored = list(map(len, (result.failures, result.errors)))
192190
if failed:
193-
self.stream.write("failures=%d" % failed)
191+
self.stream.write(f"failures={failed}")
194192
if errored:
195193
if failed:
196194
self.stream.write(", ")
197-
self.stream.write("errors=%d" % errored)
195+
self.stream.write(f"errors={errored}")
198196
self.stream.writeln(")")
199197
else:
200198
self.stream.writeln("OK")

comtypes/typeinfo.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,7 @@ class tagTLIBATTR(ctypes.Structure):
681681
wLibFlags: int
682682

683683
def __repr__(self):
684-
return "TLIBATTR(GUID=%s, Version=%s.%s, LCID=%s, FLags=0x%x)" % (
685-
self.guid,
686-
self.wMajorVerNum,
687-
self.wMinorVerNum,
688-
self.lcid,
689-
self.wLibFlags,
690-
)
684+
return f"TLIBATTR(GUID={self.guid}, Version={self.wMajorVerNum}.{self.wMinorVerNum}, LCID={self.lcid}, FLags=0x{self.wLibFlags:x})"
691685

692686

693687
TLIBATTR = tagTLIBATTR
@@ -716,13 +710,7 @@ class tagTYPEATTR(ctypes.Structure):
716710
idldescType: "IDLDESC"
717711

718712
def __repr__(self):
719-
return "TYPEATTR(GUID=%s, typekind=%s, funcs=%s, vars=%s, impltypes=%s)" % (
720-
self.guid,
721-
self.typekind,
722-
self.cFuncs,
723-
self.cVars,
724-
self.cImplTypes,
725-
)
713+
return f"TYPEATTR(GUID={self.guid}, typekind={self.typekind}, funcs={self.cFuncs}, vars={self.cVars}, impltypes={self.cImplTypes})"
726714

727715

728716
TYPEATTR = tagTYPEATTR
@@ -746,14 +734,14 @@ class tagFUNCDESC(ctypes.Structure):
746734

747735
def __repr__(self):
748736
return (
749-
"FUNCDESC("
737+
f"FUNCDESC("
750738
f"memid={self.memid}, "
751739
f"cParams={self.cParams}, "
752740
f"cParamsOpt={self.cParamsOpt}, "
753741
f"callconv={self.callconv}, "
754-
f"invkind={self.invkind,}, "
742+
f"invkind={self.invkind}, "
755743
f"funckind={self.funckind}"
756-
")"
744+
f")"
757745
)
758746

759747

0 commit comments

Comments
 (0)