Skip to content

Commit

Permalink
Refactor from % string formatting to f-strings (#699)
Browse files Browse the repository at this point in the history
* refactored packing error messages to use f-strings

* using fstring
  • Loading branch information
newwingbird authored Dec 14, 2024
1 parent 8014913 commit 63b7f00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
8 changes: 4 additions & 4 deletions comtypes/tools/codegenerator/packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions comtypes/tools/typedesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ def __init__(
self.doc = doc

def __repr__(self):
return "<TypeLib(%s: %s, %s, %s)>" % (
self.name,
self.guid,
self.major,
self.minor,
)
return f"<TypeLib({self.name}: {self.guid}, {self.major}, {self.minor})>"


class Constant(object):
Expand Down
6 changes: 1 addition & 5 deletions comtypes/viewobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ def __init__(self, *args, **kw):

def __repr__(self):
size = (self.sizelProposed.cx, self.sizelProposed.cy)
return "<ExtentInfo(mode=%s, size=%s) at %x>" % (
self.dwExtentMode,
size,
id(self),
)
return f"<ExtentInfo(mode={self.dwExtentMode}, size={size}) at {id(self):x}>"


assert sizeof(tagExtentInfo) == 16, sizeof(tagExtentInfo)
Expand Down

0 comments on commit 63b7f00

Please sign in to comment.