From 63b7f004633c6d3902d6d43ca49e03c4146050c7 Mon Sep 17 00:00:00 2001 From: newwingbird <62642238+newwingbird@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:23:19 +0900 Subject: [PATCH] Refactor from % string formatting to f-strings (#699) * refactored packing error messages to use f-strings * using fstring --- comtypes/tools/codegenerator/packing.py | 8 ++++---- comtypes/tools/typedesc.py | 7 +------ comtypes/viewobject.py | 6 +----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/comtypes/tools/codegenerator/packing.py b/comtypes/tools/codegenerator/packing.py index a285df23..68c18fea 100644 --- a/comtypes/tools/codegenerator/packing.py +++ b/comtypes/tools/codegenerator/packing.py @@ -25,20 +25,20 @@ def _calc_packing(struct, fields, pack, isStruct): size += a - size % a if isStruct: if size != f.offset: - raise PackingError("field %s offset (%s/%s)" % (f.name, size, f.offset)) + raise PackingError(f"field {f.name} offset ({size}/{f.offset})") size += s else: size = max(size, s) total_align = max(total_align, a) if total_align != struct.align: - raise PackingError("total alignment (%s/%s)" % (total_align, struct.align)) + raise PackingError(f"total alignment ({total_align}/{struct.align})") a = total_align if pack is not None: a = min(pack, a) if size % a: size += a - size % a if size != struct.size: - raise PackingError("total size (%s/%s)" % (size, struct.size)) + raise PackingError(f"total size ({size}/{struct.size})") def calc_packing(struct, fields): @@ -55,7 +55,7 @@ def calc_packing(struct, fields): return int(pack / 8) - raise PackingError("PACKING FAILED: %s" % details) + raise PackingError(f"PACKING FAILED: {details}") class PackingError(Exception): diff --git a/comtypes/tools/typedesc.py b/comtypes/tools/typedesc.py index 66e6e0cf..8a6b9f42 100644 --- a/comtypes/tools/typedesc.py +++ b/comtypes/tools/typedesc.py @@ -20,12 +20,7 @@ def __init__( self.doc = doc def __repr__(self): - return "" % ( - self.name, - self.guid, - self.major, - self.minor, - ) + return f"" class Constant(object): diff --git a/comtypes/viewobject.py b/comtypes/viewobject.py index 84840a05..a7499ef6 100644 --- a/comtypes/viewobject.py +++ b/comtypes/viewobject.py @@ -61,11 +61,7 @@ def __init__(self, *args, **kw): def __repr__(self): size = (self.sizelProposed.cx, self.sizelProposed.cy) - return "" % ( - self.dwExtentMode, - size, - id(self), - ) + return f"" assert sizeof(tagExtentInfo) == 16, sizeof(tagExtentInfo)