-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Do not use percent format in strings #8045
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -825,8 +825,9 @@ | |||||||||||||
try: | ||||||||||||||
stream_len = int(result[b"Length"]) | ||||||||||||||
except (TypeError, KeyError, ValueError) as e: | ||||||||||||||
msg = "bad or missing Length in stream dict (%r)" % result.get( | ||||||||||||||
b"Length", None | ||||||||||||||
msg = ( | ||||||||||||||
"bad or missing Length in stream dict " | ||||||||||||||
f"({result.get(b'Length')})" | ||||||||||||||
) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
radarhere#25 feels that error message should fit onto one line. The change above this would be my suggestion for that goal. The suggestion from the PR is stream_len_str = result.get(b"Length")
try:
stream_len = int(stream_len_str)
except (TypeError, KeyError, ValueError) as e:
msg = f"bad or missing Length in stream dict ({stream_len_str})"
raise PdfFormatError(msg) from e I think that makes the code harder to read, because, if you ignore the exception, there's more to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion would be radarhere#25 (comment): try:
stream_len_str = result.get(b"Length")
stream_len = int(stream_len_str)
except (TypeError, KeyError, ValueError) as e:
msg = f"bad or missing Length in stream dict ({stream_len_str})"
raise PdfFormatError(msg) from e There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I've pushed that - minus the |
||||||||||||||
raise PdfFormatError(msg) from e | ||||||||||||||
stream_data = data[m.end() : m.end() + stream_len] | ||||||||||||||
|
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.
Can we put this in a variable outside the string, then make this an f-string?
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.
Ok, I've pushed a commit. It did require escaping brackets though.