Skip to content

Commit

Permalink
replaced by fstring
Browse files Browse the repository at this point in the history
  • Loading branch information
newwingbird committed Dec 14, 2024
1 parent 1ea74f5 commit b5fba06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
20 changes: 9 additions & 11 deletions comtypes/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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("_"):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
22 changes: 5 additions & 17 deletions comtypes/typeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")"
)


Expand Down

0 comments on commit b5fba06

Please sign in to comment.