-
Notifications
You must be signed in to change notification settings - Fork 277
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
style: Use f-strings wherever possible #600
Conversation
826d767
to
f713af4
Compare
738cd51
to
b8a6313
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for taking the time!
Have you changed them one by one and checked they all make sense? Or did you use a script to find and replace them? (in some rare cases like %02d
, %.2f
or %-10s
, f-string cannot be used as is)
b8a6313
to
1fd213a
Compare
1fd213a
to
571b67e
Compare
There are not such cases as far as I can see. Yet, it possible to write |
Sure it is! I just wanted to make sure you (or your custom script?) looked for them, if any :) I still see a few |
As for the tool I use, it's pyupgrade. But I often end up applying changes manually, because:
|
571b67e
to
abe075f
Compare
I have left an instance of |
They're faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left an instance of
%
string interpolation inyamllint/rules/line_length.py
I had spotted this one too and I agree it's better readable like this 👍
I allowed myself to force-push to your branch with a slight rework of modified strings:
--- a/yamllint/config.py
+++ b/yamllint/config.py
@@ -179,8 +179,8 @@ def validate_rule_conf(rule, conf):
continue
if optkey not in options:
raise YamlLintConfigError(
- f'invalid config: unknown option "{optkey}" '
- f'for rule "{rule.ID}"')
+ f'invalid config: unknown option "{optkey}" for rule '
+ f'"{rule.ID}"')
# Example: CONF = {option: (bool, 'mixed')}
# → {option: true} → {option: mixed}
if isinstance(options[optkey], tuple):
@@ -216,8 +216,8 @@ def validate_rule_conf(rule, conf):
raise YamlLintConfigError(f'invalid config: {rule.ID}: {res}')
else:
raise YamlLintConfigError(
- f'invalid config: rule "{rule.ID}": should be '
- f'either "enable", "disable" or a dict')
+ f'invalid config: rule "{rule.ID}": should be either "enable", '
+ f'"disable" or a dict')
return conf
--- a/yamllint/rules/indentation.py
+++ b/yamllint/rules/indentation.py
@@ -342,11 +342,11 @@ def _check(conf, token, prev, next, nextnext, context):
if found_indentation != expected:
if expected < 0:
- message = f'wrong indentation: expected ' \
- f'at least {found_indentation + 1}'
+ message = f'wrong indentation: expected at least ' \
+ f'{found_indentation + 1}'
else:
- message = f'wrong indentation: expected {expected} ' \
- f'but found {found_indentation}'
+ message = f'wrong indentation: expected {expected} but ' \
+ f'found {found_indentation}'
yield LintProblem(token.start_mark.line + 1,
found_indentation + 1, message)
Thank you Dimitri, let's merge!
They're faster.