Repository navigation
Open
Labels
good first issueGood for newcomers
Description
We could replace % string formatting with f-strings wherever applicable, as was done in #654.
For details on f-string syntax, refer to the Python official documentation.
-
Most of the changes should follow these patterns:
- Replace
"...%s..." % foowithf"...{foo}..." - Replace
"...%r..." % foowithf"...{foo!r}..." - Replace
"...%x..." % foowithf"...{foo:x}..." - Replace
"...%d..." % foowithf"...{foo:d}..." - Replace
"...\\%s..." % foowithf"...\\{foo}..." - Replace
r"...\%s..." % foowithrf"...\{foo}..."
- Replace
-
There’s NO need to modify placeholders in logger method calls, as shown below.
Lines 137 to 141 in 083c19e
def CoInitializeEx(flags=None): if flags is None: flags = getattr(sys, "coinit_flags", COINIT_APARTMENTTHREADED) logger.debug("CoInitializeEx(None, %s)", flags) _ole32.CoInitializeEx(None, flags) -
We welcome keeping changes as small as possible per pull request, as it makes it easier for reviewers to check the changes.
-
If your PR addresses multiple rules or files, reviewers might consider it a large change and suggest splitting it into multiple PRs.
TODO list
Under the comtypes/...
-
comtypes/_comobject.py -
comtypes/_memberspec.py -
comtypes/_post_coinit/_cominterface_meta_patcher.py -
comtypes/automation.py -
comtypes/client/_code_cache.py -
comtypes/client/_constants.py -
comtypes/client/_events.py -
comtypes/client/_generate.py -
comtypes/client/lazybind.py -
comtypes/errorinfo.py -
comtypes/server/inprocserver.py -
comtypes/server/register.py -
comtypes/server/w_getopt.py -
comtypes/tools/codegenerator/codegenerator.py -
comtypes/tools/codegenerator/helpers.py -
comtypes/tools/codegenerator/packing.py -
comtypes/tools/tlbparser.py -
comtypes/tools/typedesc.py -
comtypes/typeinfo.py -
comtypes/viewobject.py
Under the comtypes/test/...
-
comtypes/test/__init__.py -
comtypes/test/test_BSTR.py -
comtypes/test/test_avmc.py -
comtypes/test/test_casesensitivity.py -
comtypes/test/test_collections.py -
comtypes/test/test_comserver.py -
comtypes/test/test_createwrappers.py -
comtypes/test/test_dispinterface.py -
comtypes/test/test_excel.py -
comtypes/test/test_outparam.py -
comtypes/test/test_safearray.py -
comtypes/test/test_sapi.py -
comtypes/test/test_server.py -
comtypes/test/test_urlhistory.py -
comtypes/test/test_variant.py -
comtypes/test/test_word.py
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomers
Activity
newwingbird commentedon Nov 16, 2024
I looked for the use location by git grep -n '%[sdxXorfFeEgGc]'
I will split modification into several PRs by file or dir.
result
junkmd commentedon Nov 16, 2024
@newwingbird
Thank you for your investigation.
Please note that the grep results mentioned above include items like
logger.debug(...)and_debug(...), which fall outside the scope of this issue.Happy contributing!
newwingbird commentedon Nov 16, 2024
@junkmd Thank you for your support.
I investigated by
git grep -n '%[sdxXorfFeEgGc]' | grep -v 'logger\.debug' | grep -v '_debug'I found the reduction of the applicable code . I will try this .
Result
junkmd commentedon Nov 16, 2024
Hi @newwingbird,
Thanks for your quick response.
I noticed that
_debug,_warning,logger.info, and.CPPfiles are included.newwingbird commentedon Nov 16, 2024
@junkmd
Okay, In addition,
_errortoo?This issue's scope is only inside
printand string literal ?junkmd commentedon Nov 16, 2024
@newwingbird
I might have missed it, but if
_errorexists, it would similarly fall outside the scope of this issue.That's right.
junkmd commentedon Nov 17, 2024
We became confused about the combination of
\,\\,rf, andrin #667.To avoid further confusion while working on this issue, I’ve added examples to the kanban.
As shown below, these patterns are equivalent regardless of the chosen style.
However, to keep changes minimal, let’s ensure the number of backslashes remains the same before and after changes within the scope of this issue.
We can decide whether to standardize them after this issue is closed.
junkmd commentedon Nov 18, 2024
@newwingbird
The
.pyfiles outside thecomtypes/...directory have not been maintained for many years, and simply replacing them with f-strings will not improve readability or modernize the codebase.Can you accept to limit the scope of this issue to the
.pyfiles within thecomtypes/...directory?newwingbird commentedon Nov 18, 2024
I think so. We should replan the scope of issues.
junkmd commentedon Nov 18, 2024
Thank you for agreeing.
I have removed "Others" from the kanban and limited the to-do list to only the
.pyfiles under thecomtypes/....Please keep up the great work as a contributor!