Skip to content

Refactor from % string formatting to f-strings in every module. #657

@junkmd

Description

@junkmd

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..." % foo with f"...{foo}..."
    • Replace "...%r..." % foo with f"...{foo!r}..."
    • Replace "...%x..." % foo with f"...{foo:x}..."
    • Replace "...%d..." % foo with f"...{foo:d}..."
    • Replace "...\\%s..." % foo with f"...\\{foo}..."
    • Replace r"...\%s..." % foo with rf"...\{foo}..."
  • There’s NO need to modify placeholders in logger method calls, as shown below.

    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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions