Add Type Annotations for parts of pwnlib/util#2679
Add Type Annotations for parts of pwnlib/util#2679SmoothHacker wants to merge 7 commits intoGallopsled:devfrom
Conversation
|
Should type annotations be added to docs? So user can know arg types when reading documentation. |
|
I believe the type hints can be made a bit modular, this would require some thought. For one, I think we use a lot of bytes|bytearray|memoryview. There should already be a stdlib type (BytesLike?) for that. We also use a lot of BytesLike|str (maybe call it Ascii? There are many places where only valid chars/codepoints are indeed ascii). Try to look for other examples of commonly appearing nontrivial types and add them e.g. to a new module called pwntools._typehints or pwntools.typing etc. Try to look at other well typed Python projects for inspiration. |
There should be a way to configure readthedocs to incorporate the type hints. I can look into that quickly.
I can make the longer type hints more neater with "super types" like BytesLike or AsciiLike as you described |
4e75d36 to
f5b83af
Compare
I found that sphinx will automatically extract function signature with type hints, without explicitly write it in doc string. Never mind. |
e66825a to
b8b3bb2
Compare
|
@RocketMaDev this PR should be ready to go |
I used ruff to flag areas of pwnlib/util that are missing type annotations. This is what I have done so far. If this looks good then I can proceed with other parts of the code base.