Skip to content

Updating by fstring - #667

Merged
junkmd merged 21 commits into
enthought:mainfrom
newwingbird:update-by-fstring
Nov 21, 2024
Merged

junkmd merged 21 commits into
enthought:mainfrom
newwingbird:update-by-fstring

Conversation

@newwingbird

@newwingbird newwingbird commented Nov 17, 2024 •

Copy link
Copy Markdown
Contributor

Related to #657

Out of scope

  • comtypes/client/init.py
  • comtypes/server/connectionpoints.py
  • comtypes/client/init.py
  • comtypes/server/connectionpoints.py

Note

I investigated by git grep -n '%[sdxXorfFeEgGc]' | grep -v 'logger\.debug' | grep -v '_debug' | grep -v '_warning' | grep -v 'logger\.info' | grep -v '_error'

The following code would be listed with this command.
So Issue's todo list will be changed.

            _error(
                "Exception in %s.%s implementation:",
                interface.__name__,
                mthname,
                exc_info=True,
            )

@newwingbird newwingbird changed the title Update by fstring Updating by fstring Nov 17, 2024
Comment thread comtypes/client/_code_cache.py Resolved
Comment thread comtypes/server/register.py Resolved
@junkmd junkmd added the coding style Topics related to style, formatters, linters, and delinting. label Nov 17, 2024
@junkmd junkmd added this to the 1.4.9 milestone Nov 17, 2024
@junkmd

junkmd commented Nov 17, 2024 •

Copy link
Copy Markdown
Collaborator

Out of scope

  • comtypes/client/init.py
  • comtypes/server/connectionpoints.py
  • comtypes/client/init.py
  • comtypes/server/connectionpoints.py

The following code would be listed with this command. So Issue's todo list will be changed.

            _error(
                "Exception in %s.%s implementation:",
                interface.__name__,
                mthname,
                exc_info=True,
            )

Good catch!
I will remove them from the issue kanban.

Comment thread comtypes/client/_events.py Resolved
Comment thread comtypes/client/_code_cache.py Resolved
Comment thread comtypes/server/register.py Resolved

@junkmd junkmd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append(… could likely be replaced with f-strings for other lines as well.

Comment thread comtypes/server/register.py Resolved
Comment thread comtypes/client/_code_cache.py Resolved
Comment thread comtypes/server/register.py Resolved
@junkmd

junkmd commented Nov 17, 2024

Copy link
Copy Markdown
Collaborator

To avoid further confusion while working on this issue, I’ve added examples to the issue kanban.

  • Replace "...\\%s..." % foo with f"...\\{foo}..."
  • Replace r"...\%s..." % foo with rf"...\{foo}..."

#657 (comment)

Comment thread comtypes/server/register.py Resolved
junkmd added a commit to junkmd/pywinauto that referenced this pull request Nov 20, 2024
Comment thread comtypes/server/register.py Resolved
Comment thread comtypes/errorinfo.py Resolved
if hasattr(head.struct, "_recordinfo_"):
print(
" _recordinfo_ = %r" % (head.struct._recordinfo_,),
f" _recordinfo_ = {head.struct._recordinfo_!r}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit complicated, but it's equivalent, so there's no problem.

>>> info = ('{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}', 1, 0, 0, '{00FABB0F-5691-41A6-B7C1-11606671F8E5}')
>>> f" _recordinfo_ = {info!r}"
" _recordinfo_ = ('{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}', 1, 0, 0, '{00FABB0F-5691-41A6-B7C1-11606671F8E5}')"
>>> " _recordinfo_ = %r" % (info,)
" _recordinfo_ = ('{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}', 1, 0, 0, '{00FABB0F-5691-41A6-B7C1-11606671F8E5}')"

junkmd added a commit to junkmd/pywinauto that referenced this pull request Nov 20, 2024
junkmd added a commit to junkmd/pywinauto that referenced this pull request Nov 20, 2024

@junkmd junkmd left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your efforts.

I’ve reviewed several PRs related to #657 and have come to the conclusion that the optimal amount of changes for this type of replacement is about 30 lines per PR.

Of course, there may be cases related to #657 where changes exceeding 30 lines are necessary for a single file. In such cases, please create a PR for that file only.

@junkmd
junkmd merged commit fb15f91 into enthought:main Nov 21, 2024
@junkmd junkmd linked an issue Nov 21, 2024 that may be closed by this pull request
27 of 36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coding style Topics related to style, formatters, linters, and delinting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants