Skip to content

Prefer f-strings instead of str.format - #2164

Closed
WhyNotHugo wants to merge 1 commit into
jazzband:mainfrom
WhyNotHugo:f-strings
Closed

Prefer f-strings instead of str.format#2164
WhyNotHugo wants to merge 1 commit into
jazzband:mainfrom
WhyNotHugo:f-strings

Conversation

@WhyNotHugo

Copy link
Copy Markdown
Member

No user facing changes.

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if pyupgrade could've handled this.

Comment thread piptools/resolver.py
@@ -429,9 +429,9 @@ def get_best_match(self, ireq: InstallRequirement) -> InstallRequirement:

# Format the best match
log.debug(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Logging is supposed to pass params through dedicated arguments, though. Instead of pre-rendering strings before passing them into logging..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's exactly what my change does.

Previously a pre-rendered string was being passed (one using .format()). Now dedicated arguments are passed.

@WhyNotHugo

WhyNotHugo commented Feb 19, 2025

Copy link
Copy Markdown
Member Author

I wonder if pyupgrade could've handled this.

Ruff's pyupgrade re-implementation does handle this. This PR and #2163 are groundwork for using ruff instead of flake8+pyupgrade, but can be merged independently.

@WhyNotHugo

Copy link
Copy Markdown
Member Author

Not sure about th CI failures. Rebased onto latest main.

@sirosen

sirosen commented Jun 27, 2025

Copy link
Copy Markdown
Member

I think pyupgrade would, indeed, handle a couple of these and is a good idea (original implementation or ruff) regardless for the numerous other fixes it applies. But that's doesn't block this PR.

I've hit the GitHub rebase button since a lot of CI has been fixed significantly at this point.
I was hoping CI would be clean, but there still appear to be errors, which is disappointing.

@WhyNotHugo WhyNotHugo closed this by deleting the head repository Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants