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
refactor: use f-strings across codebase #768
refactor: use f-strings across codebase #768
Conversation
1000+ lines of changes 😰 I looked at maybe 100+ of them, all looks ok 😄 |
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, but looks like you missed some. Also we can probably use this PR to clean up a lot of unneeded :s
or :c
or 0xf"{...:x}"
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'd grep for that str()
pattern.
A few comments to address, let's get this merged! |
I actually tried implementing your comments (not just the lines you mentioned but in regards to the pattern) and messed everything up because I got confused with the types. That's why I focused on the "Type Hints" PR first and wanted to fix this one afterwards. |
OK fair |
@theguy147 I will stop developing on this branch (after 5f641bb) so you can now adjust the conflicts. Some more commits might land, but only affect Cheers |
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 mostly good, but a few things:
Most :s
are probably unnecessary.
All str()
should be unnecessary. Can use !s
if we really have to. It does the same thing.
Also, the diff looks messed up. I suggest you squash and then rebase to clean it up.
076d565
to
ef19244
Compare
4238d69
to
7b71465
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.
Reviewed lines 1-6500
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.
Done reviewing. A few nits. Thanks for your patience.
… gdb_8_py36_code_refactor
# backward compat for gdb (gdb < 7.10) | ||
if not hasattr(gdb, "FrameDecorator"): | ||
gdb.execute("backtrace {:d}".format(nb_backtrace)) | ||
gdb.execute(f"backtrace {nb_backtrace:d}") | ||
return |
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.
It has nothing to do with your PR but since we now baseline gdb to be 8, can you remove this block?
# backward compat for gdb (gdb < 7.10) | |
if not hasattr(gdb, "FrameDecorator"): | |
gdb.execute("backtrace {:d}".format(nb_backtrace)) | |
gdb.execute(f"backtrace {nb_backtrace:d}") | |
return |
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.
Added to project https://github.com/hugsy/gef/projects/11#card-75928305
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.
So should I still commit the suggested fix or now that it was added to the project to track, we do that in a future code change?
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.
Future one
memalign = gef.arch.ptrsize | ||
|
||
offset = idx * memalign | ||
current_address = align_address(addr + offset) | ||
addrs = dereference_from(current_address) | ||
l = "" | ||
addr_l = format_address(int(addrs[0], 16)) | ||
l += "{:s}{:s}{:+#07x}: {:{ma}s}".format(Color.colorify(addr_l, base_address_color), | ||
l += "{}{}{:+#07x}: {:{ma}s}".format(Color.colorify(addr_l, base_address_color), |
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.
Any reason you didn't f-string this one?
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.
Good eye, also the args on the next line aren't lined up.
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.
There are a few format-strings that I didn't convert to f-strings yet. When I didn't convert them it was mostly because I was concerned with worsening the readability. In this case the part I wasn't sure about is {:{ma}s}
. This line would turn into:
l += f"{Color.colorify(addr_l, base_address_color)}{VERTICAL_LINE}{base_offset+offset:+#07x}: {sep.join(addrs[1:]):{memalign*2+2}s}"
I can include this and similar strings as well if you think that it improves the code quality overall (at least for the aspect of consistency)
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.
Yeah fair. We shouldn't be married to f strings if it makes things harder to read (but please fix the alignment of the args)
refactor: use f-strings across codebase
Description/Motivation/Screenshots
This PR replaces all
.format(...)
and%
strings with f-strings.How Has This Been Tested?
make test
test_cmd_elf_info
already failed on this branch before this PRChecklist
gdb_8_py36_code_refactor
branch, notmaster
.