Skip to content

Commit fd8bfa7

Browse files
committed
Prefer more f-strings and non-printf-style format
1 parent 60d7236 commit fd8bfa7

36 files changed

Lines changed: 102 additions & 317 deletions

Pythonwin/pywin/framework/app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ def __init__(self, idd=win32ui.IDD_ABOUTBOX):
334334
dialog.Dialog.__init__(self, idd)
335335

336336
def OnInitDialog(self):
337-
text = "Pythonwin - Python IDE and GUI Framework for Windows.\n\n{}\n\nPython is {}\n\n{}\n\n{}\n\n{}".format(
338-
win32ui.copyright, sys.copyright, scintilla, idle, contributors
339-
)
337+
text = f"Pythonwin - Python IDE and GUI Framework for Windows.\n\n{win32ui.copyright}\n\nPython is {sys.copyright}\n\n{scintilla}\n\n{idle}\n\n{contributors}"
340338
self.SetDlgItemText(win32ui.IDC_EDIT1, text)
341339
# Get the build number - written by installers.
342340
# For distutils build, read pywin32.version.txt

Pythonwin/pywin/framework/editor/document.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,13 @@ def CheckExternalDocumentUpdated(self):
158158
except OSError as exc:
159159
if not self.bReportedFileNotFound:
160160
print(
161-
"The file '{}' is open for editing, but\nchecking it for changes caused the error: {}".format(
162-
self.GetPathName(), exc.strerror
163-
)
161+
f"The file '{self.GetPathName()}' is open for editing, but\nchecking it for changes caused the error: {exc.strerror}"
164162
)
165163
self.bReportedFileNotFound = 1
166164
return
167165
if self.bReportedFileNotFound:
168166
print(
169-
"The file '{}' has re-appeared - continuing to watch for changes...".format(
170-
self.GetPathName()
171-
)
167+
f"The file '{self.GetPathName()}' has re-appeared - continuing to watch for changes..."
172168
)
173169
self.bReportedFileNotFound = (
174170
0 # Once found again we want to start complaining.

Pythonwin/pywin/framework/interact.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ def Init(self):
337337
f"PythonWin {sys.version} on {sys.platform}{suffix}.\n"
338338
)
339339
sys.stderr.write(
340-
"Portions {} - see 'Help/About PythonWin' for further copyright information.\n".format(
341-
win32ui.copyright
342-
)
340+
f"Portions {win32ui.copyright} - see 'Help/About PythonWin' for further copyright information.\n"
343341
)
344342
else:
345343
sys.stderr.write(self.banner)

Pythonwin/pywin/framework/intpyapp.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def ProcessArgs(self, args, dde=None):
317317
# pywin.scintilla.document.CScintillaDocument.OnOpenDocument)
318318
# segfaults Pythonwin on recent PY3 builds (b228)
319319
win32ui.MessageBox(
320-
"No such file: {}\n\nCommand Line: {}".format(
321-
fname, win32api.GetCommandLine()
322-
),
320+
f"No such file: {fname}\n\nCommand Line: {win32api.GetCommandLine()}",
323321
"Open file for edit",
324322
win32con.MB_ICONERROR,
325323
)

Pythonwin/pywin/scintilla/IDLEenvironment.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,7 @@ def TestGet(fr, to, t, expected):
517517
got = t.get(fr, to)
518518
if got != expected:
519519
print(
520-
"ERROR: get({}, {}) expected {}, but got {}".format(
521-
repr(fr), repr(to), repr(expected), repr(got)
522-
)
520+
f"ERROR: get({repr(fr)}, {repr(to)}) expected {repr(expected)}, but got {repr(got)}"
523521
)
524522

525523

Pythonwin/pywin/scintilla/view.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ def AppendMenu(self, menu, text="", event=None, flags=None, checked=0):
334334
if cmdid is None:
335335
# No event of that name - no point displaying it.
336336
print(
337-
'View.AppendMenu(): Unknown event "{}" specified for menu text "{}" - ignored'.format(
338-
event, text
339-
)
337+
f'View.AppendMenu(): Unknown event "{event}" specified for menu text "{text}" - ignored'
340338
)
341339
return
342340
keyname = configManager.get_key_binding(event, self._GetSubConfigNames())
@@ -512,9 +510,7 @@ def list2dict(l):
512510
pass
513511
except:
514512
win32ui.SetStatusText(
515-
"Error attempting to get object attributes - {}".format(
516-
repr(sys.exc_info()[0])
517-
)
513+
f"Error attempting to get object attributes - {repr(sys.exc_info()[0])}"
518514
)
519515

520516
# ensure all keys are strings.
@@ -824,9 +820,8 @@ def LoadConfiguration():
824820
configManager = ConfigManager(configName)
825821
if configManager.last_error:
826822
bTryDefault = 0
827-
msg = "Error loading configuration '{}'\n\n{}".format(
828-
configName,
829-
configManager.last_error,
823+
msg = (
824+
f"Error loading configuration '{configName}'\n\n{configManager.last_error}"
830825
)
831826
if configName != "default":
832827
msg += "\n\nThe default configuration will be loaded."

Pythonwin/pywin/tools/hierlist.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def HierInit(self, parent, listControl=None): # Used when window first exists.
9999
lbid = listControl.GetDlgCtrlID()
100100
assert (
101101
self.listBoxId is None or self.listBoxId == lbid
102-
), "An invalid listbox control ID has been specified (specified as {}, but exists as {})".format(
103-
self.listBoxId, lbid
104-
)
102+
), f"An invalid listbox control ID has been specified (specified as {self.listBoxId}, but exists as {lbid})"
105103
self.listBoxId = lbid
106104
self.listControl.SetImageList(self.imageList, commctrl.LVSIL_NORMAL)
107105
# self.list.AttachObject(self)

Pythonwin/pywin/tools/regedit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,8 @@ def __eq__(self, other):
332332
)
333333

334334
def __repr__(self):
335-
return "<{} with root={}, key={}>".format(
336-
self.__class__.__name__,
337-
self.keyRoot,
338-
self.keyName,
335+
return (
336+
f"<{self.__class__.__name__} with root={self.keyRoot}, key={self.keyName}>"
339337
)
340338

341339
def GetText(self):

com/win32com/client/build.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def __init__(
9999

100100
def __repr__(self):
101101
return (
102-
"MapEntry(dispid={s.dispid}, desc={s.desc}, names={s.names}, doc={s.doc!r}, "
103-
"resultCLSID={s.resultCLSID}, resultDocumentation={s.resultDocumentation}, "
104-
"wasProperty={s.wasProperty}, hidden={s.hidden}"
105-
).format(s=self)
102+
f"MapEntry(dispid={self.dispid}, desc={self.desc}, names={self.names}, doc={self.doc!r}, "
103+
f"resultCLSID={self.resultCLSID}, resultDocumentation={self.resultDocumentation}, "
104+
f"wasProperty={self.wasProperty}, hidden={self.hidden}"
105+
)
106106

107107
def GetResultCLSID(self):
108108
rc = self.resultCLSID
@@ -424,18 +424,12 @@ def MakeDispatchFuncMethod(self, entry, name, bMakeClass=1):
424424
)
425425
s += f"{linePrefix}\tif ret is not None:\n"
426426
if rd == pythoncom.VT_UNKNOWN:
427-
s += "{}\t\t# See if this IUnknown is really an IDispatch\n".format(
428-
linePrefix
429-
)
427+
s += f"{linePrefix}\t\t# See if this IUnknown is really an IDispatch\n"
430428
s += f"{linePrefix}\t\ttry:\n"
431-
s += "{}\t\t\tret = ret.QueryInterface(pythoncom.IID_IDispatch)\n".format(
432-
linePrefix
433-
)
429+
s += f"{linePrefix}\t\t\tret = ret.QueryInterface(pythoncom.IID_IDispatch)\n"
434430
s += f"{linePrefix}\t\texcept pythoncom.error:\n"
435431
s += f"{linePrefix}\t\t\treturn ret\n"
436-
s += "{}\t\tret = Dispatch(ret, {}, {})\n".format(
437-
linePrefix, repr(name), resclsid
438-
)
432+
s += f"{linePrefix}\t\tret = Dispatch(ret, {repr(name)}, {resclsid})\n"
439433
s += "%s\treturn ret" % linePrefix
440434
elif rd == pythoncom.VT_BSTR:
441435
s = f"{linePrefix}\t# Result is a Unicode object\n"

com/win32com/client/dynamic.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,7 @@ def _FlagAsMethod(self, *methodNames):
533533

534534
def __AttrToID__(self, attr):
535535
debug_attr_print(
536-
"Calling GetIDsOfNames for property {} in Dispatch container {}".format(
537-
attr, self._username_
538-
)
536+
f"Calling GetIDsOfNames for property {attr} in Dispatch container {self._username_}"
539537
)
540538
return self._oleobj_.GetIDsOfNames(0, attr)
541539

@@ -638,9 +636,7 @@ def __setattr__(self, attr, value):
638636
return
639637
# Allow property assignment.
640638
debug_attr_print(
641-
"SetAttr called for {}.{}={} on DispatchContainer".format(
642-
self._username_, attr, repr(value)
643-
)
639+
f"SetAttr called for {self._username_}.{attr}={repr(value)} on DispatchContainer"
644640
)
645641

646642
if self._olerepr_:
@@ -689,9 +685,7 @@ def __setattr__(self, attr, value):
689685
self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
690686
self._olerepr_.propMap[attr] = entry
691687
debug_attr_print(
692-
"__setattr__ property {} (id=0x{:x}) in Dispatch container {}".format(
693-
attr, entry.dispid, self._username_
694-
)
688+
f"__setattr__ property {attr} (id=0x{entry.dispid:x}) in Dispatch container {self._username_}"
695689
)
696690
return
697691
except pythoncom.com_error:

0 commit comments

Comments
 (0)