Avoid repeating function calls in f-string conversions#10265
Merged
charliermarsh merged 1 commit intomainfrom Mar 7, 2024
Merged
Avoid repeating function calls in f-string conversions#10265charliermarsh merged 1 commit intomainfrom
charliermarsh merged 1 commit intomainfrom
Conversation
Member
Author
|
We could arguably make this an unsafe fix, but I think it's unlikely to be a desirable change for users. |
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| UP032 | 4 | 0 | 4 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+0 -4 violations, +0 -0 fixes in 3 projects; 40 projects unchanged)
pypa/pip (+0 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- tests/functional/test_install.py:269:9: UP032 Use f-string instead of `format` call
zulip/zulip (+0 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- corporate/lib/stripe.py:2207:28: UP032 Use f-string instead of `format` call
indico/indico (+0 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- indico/core/db/sqlalchemy/custom/greatest.py:24:12: UP032 Use f-string instead of `format` call - indico/core/db/sqlalchemy/custom/least.py:24:12: UP032 Use f-string instead of `format` call
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| UP032 | 4 | 0 | 4 | 0 | 0 |
Member
Author
|
\cc @ThiefMaster who filed this |
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
## Summary
Given a format string like `"{x} {x}".format(x=foo())`, we should avoid
converting to an f-string, since doing so would require repeating the
function call (`f"{foo()} {foo()}"`), which could introduce side
effects.
Closes astral-sh#10258.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Given a format string like
"{x} {x}".format(x=foo()), we should avoid converting to an f-string, since doing so would require repeating the function call (f"{foo()} {foo()}"), which could introduce side effects.Closes #10258.