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

refactor: add type hints #774

Merged
merged 13 commits into from
Jan 9, 2022

Conversation

theguy147
Copy link
Collaborator

@theguy147 theguy147 commented Jan 7, 2022

refactor: add type hints

Description/Motivation/Screenshots

This huge PR adds type hints to the gdb8/py36 refactor branch and thereby reveals some logical bugs that can be addressed moving forward.

(Probably this PR does not cover 100% of the places where python 3.6. typing hints could be added but I wanted to push it already because I'm not sure about my schedule these next days)

How Has This Been Tested?

Architecture Yes/No Comments
x86-32 ✔️
x86-64 ✔️
ARM ✖️
AARCH64 ✖️
MIPS ✖️
POWERPC ✖️
SPARC ✖️
RISC-V ✖️
make test ✔️ On my local machine 2 tests fail (not related to this PR though)
make lint ✔️

Checklist

  • My PR was done against the gdb_8_py36_code_refactor branch, not master.
  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • My change adds tests as appropriate.
  • I have read and agree to the CONTRIBUTING document.

EDIT:
The PR was tested with python version 3.6 to be sure of compatibility

EDIT:
Just FYI: The tests that fail on my local machine are test_cmd_elf_info and test_cmd_unicorn_emulate. And I also set up a CI with docker and ubuntu 18.04 and 20.04 where only test_cmd_set_permission fails (but not the above mentioned). still haven't figured out why that is,

Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

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

Reviewed to line 2000

@@ -220,19 +223,19 @@ def highlight_text(text):
return "".join(ansiSplit)


def gef_print(x="", *args, **kwargs):
def gef_print(x: str = "", *args: Tuple, **kwargs: Dict) -> Optional[int]:
"""Wrapper around print(), using string buffering feature."""
x = highlight_text(x)
if gef.ui.stream_buffer and not is_debug():
return gef.ui.stream_buffer.write(x + kwargs.get("end", "\n"))
return print(x, *args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

weird. Why do we return print here? Mind changing to print then return? This whole function can probably just return None, actually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually encountered quite some similar questionable practices along the way ;)

In regards to changing this code in this PR: If I were to start changing things so it makes more sense this PR will become even huger and very confusing. IMO code changes should be implemented in separate PRs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

which is fine, but we will forget unless we note this done somewhere. Maybe make another issue and just add notes from this PR for things to fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I opened a project for this at https://github.com/hugsy/gef/projects/11

gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

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

Reviewed lines 2000-4000

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

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

Reviewed lines 4000-10000

gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Grazfather Grazfather left a comment

Choose a reason for hiding this comment

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

Reviewed to end of file

gef.py Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Outdated Show resolved Hide resolved
gef.py Show resolved Hide resolved
@Grazfather
Copy link
Collaborator

Looks good to me! Since this is targeting @hugsy 's branch let's make sure he's OK merging into it.

@Grazfather Grazfather merged commit 1a430d5 into hugsy:gdb_8_py36_code_refactor Jan 9, 2022
@theguy147 theguy147 deleted the refactor_types branch January 9, 2022 19:33
@hugsy hugsy added this to the Release: next milestone Jan 9, 2022
@hugsy hugsy moved this from In Progress to Done in Code Changes related to Type Hints Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants