Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating by fstring #667

Merged
merged 21 commits into from
Nov 21, 2024
Merged

Updating by fstring #667

merged 21 commits into from
Nov 21, 2024

Conversation

newwingbird
Copy link
Contributor

@newwingbird newwingbird commented Nov 17, 2024

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
comtypes/client/_code_cache.py Outdated Show resolved Hide resolved
comtypes/server/register.py Outdated Show resolved Hide 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
Copy link
Collaborator

junkmd commented Nov 17, 2024

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.

comtypes/client/_events.py Outdated Show resolved Hide resolved
comtypes/client/_code_cache.py Outdated Show resolved Hide resolved
comtypes/server/register.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@junkmd junkmd left a comment

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.

comtypes/server/register.py Outdated Show resolved Hide resolved
comtypes/client/_code_cache.py Outdated Show resolved Hide resolved
comtypes/server/register.py Outdated Show resolved Hide resolved
@junkmd
Copy link
Collaborator

junkmd commented Nov 17, 2024

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)

comtypes/server/register.py Outdated Show resolved Hide resolved
comtypes/tools/codegenerator/codegenerator.py Outdated Show resolved Hide resolved
comtypes/tools/codegenerator/codegenerator.py Outdated Show resolved Hide resolved
comtypes/tools/codegenerator/codegenerator.py Outdated Show resolved Hide resolved
comtypes/tools/codegenerator/codegenerator.py Outdated Show resolved Hide resolved
comtypes/tools/codegenerator/codegenerator.py Outdated Show resolved Hide resolved
junkmd added a commit to junkmd/pywinauto that referenced this pull request Nov 20, 2024
comtypes/server/register.py Outdated Show resolved Hide resolved
comtypes/errorinfo.py Outdated Show resolved Hide resolved
if hasattr(head.struct, "_recordinfo_"):
print(
" _recordinfo_ = %r" % (head.struct._recordinfo_,),
f" _recordinfo_ = {head.struct._recordinfo_!r}",
Copy link
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
Copy link
Collaborator

@junkmd junkmd left a comment

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
49 checks passed
@junkmd junkmd linked an issue Nov 21, 2024 that may be closed by this pull request
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