-
Notifications
You must be signed in to change notification settings - Fork 266
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
Use f-strings for formatting strings #743
Merged
Merged
Conversation
This file contains 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
What linter are you using? |
@Paebbels, see:
In this case, pycodestyle is passing, and pylint is failing. So: vunit/tests/lint/test_pylint.py Lines 26 to 33 in 14b5ad1
and https://github.com/VUnit/vunit/blob/master/tests/lint/pylintrc. |
6 tasks
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.
Currently, we are using a deprecated syntax (
"some text %s" % variable
) for formatting strings. CI linting is complaining about it.There are three alternatives:
"some text %s".format(variable)"
f"some text {variable}"
"some text" + str(variable)
It seems that the official syntax going forward is the second one only (f-strings). I tried using the first one, but linters would still complain. With regard to the last one, that is not desirable I think, however, in some cases I found it necessary because I couldn't make it work using f-strings.
In this PR, most of the sources in the codebase are modified for using f-strings instead of
"some text %s" % variable
or"some text %s".format(variable)"
. The remaining sources belong tovunit/sim_if
. I "fixed" those already, but I cannot test all of them. Hence, I decided to include theghdl.py
only, and handle those in an upcoming PR.I followed the following guidelines:
%s
with{VARIABLE!s}
.%r
with{VARIABLE!r}
.%i
with{VARIABLE:d}
.%.1f
with{VARIABLE:.1f}
."%s\n" % " ".join(cmd)
with" ".join(cmd) + "\n"
, and"%s\n" % ("=" * (max(max_len + 25, 0)))
with("=" * (max(max_len + 25, 0))) + "\n"
.