Skip to content
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

Merged
merged 4 commits into from
Jul 3, 2024

Conversation

L77H
Copy link
Contributor

@L77H L77H commented Jun 27, 2024

Description of the changes being introduced by the pull request:

  • "UP" added to selected rules in pyproject.toml
  • fixed 44 code errors (UP032, UP012, UP008, UP004, UP031) to comply with UP rules

Fixes #834

@L77H L77H changed the title pyupgrade linting rules integration, code fixes to comply pyupgrade "UP" linting rules integration, code fixes to comply Jun 27, 2024
Copy link
Collaborator

@jku jku left a 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),
Copy link
Collaborator

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

Copy link
Contributor Author

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('"', '\\"'))
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

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

Looks great!

@lukpueh lukpueh merged commit 9a45179 into secure-systems-lab:main Jul 3, 2024
14 checks passed
@L77H L77H deleted the UP-ruleset-ruff-linter branch July 3, 2024 09:07
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.

linter: ruff coverage
3 participants