-
Notifications
You must be signed in to change notification settings - Fork 50
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
pyupgrade "UP" linting rules integration, code fixes to comply #836
Conversation
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.
This looks good to me and was not as scary as I thought it would be: almost every str.format() call happens when building error and log messages. The only interesting changes are
- one critical line being changed in the canonicalization code: I left a comment there
- some gpg command line building: these seem ok too
@lukpueh I wouldn't mind you having a look as well
@@ -886,7 +877,7 @@ def parse_signature_packet( | |||
signature = handler.get_signature_params(data[ptr:]) | |||
|
|||
signature_data = { | |||
"keyid": "{}".format(keyid), |
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 suppose this could be just "keyid": keyid,
but I I think as a pure conversion commit this is fine too
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.
Yes, this line makes no sense like this, will change to "keyid": keyid
@@ -42,7 +42,7 @@ def _canonical_string_encoder(string): | |||
A string with the canonical-encoded 'string' embedded. | |||
""" | |||
|
|||
string = '"%s"' % string.replace("\\", "\\\\").replace('"', '\\"') | |||
string = '"{}"'.format(string.replace("\\", "\\\\").replace('"', '\\"')) |
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.
this seems to be the important line in this patch -- everythings else is error messages or otherwise non-critical. This seems correct to me.
I assume the reason for using format() here is the "quote-quoting" that would be tricky with f-strings?
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.
Yes the issue is with the .replace('"', '\\"')
. I guess we can turn it into an f-string by escaping these quotes, using format might be more readable in the end though.
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 am mistaken, backslashes are not allowed inside the f-string expression. Keeping it as is will be the most readable solution and is accepted by the linter.
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 great!
Description of the changes being introduced by the pull request:
"UP"
added to selected rules in pyproject.tomlFixes #834